File: inst.R

package info (click to toggle)
r-cran-pkgload 1.5.0-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 1,164 kB
  • sloc: sh: 13; cpp: 9; ansic: 8; makefile: 2
file content (30 lines) | stat: -rw-r--r-- 836 bytes parent folder | download | duplicates (5)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
#' Get the installation path of a package
#'
#' Given the name of a package, this returns a path to the installed
#' copy of the package, which can be passed to other devtools functions.
#'
#' It searches for the package in [.libPaths()]. If multiple
#' dirs are found, it will return the first one.
#'
#' @param name the name of a package.
#'
#' @examples
#' inst("pkgload")
#' inst("grid")
#' @export
inst <- function(name) {
  # It would be nice to use find.package or system.file, but they
  # also search in the directory in the 'path' attribute of the
  # package environment.

  # Look in the library paths
  paths <- file.path(.libPaths(), name)
  paths <- paths[dir.exists(paths)]

  if (length(paths) > 0) {
    # If multiple matches, return the first one
    return(normalizePath(paths[1]))
  } else {
    return(NULL)
  }
}