R: Search Paths for Packages (original) (raw)
libPaths {base} | R Documentation |
---|
Description
.libPaths
gets/sets the library trees within which packages are looked for.
Usage
.libPaths(new, include.site = TRUE)
.Library
.Library.site
Arguments
new | a character vector with the locations of R library trees. Tilde expansion (path.expand) is done, and if any element contains one of *?[, globbing is done where supported by the platform: see Sys.glob. |
---|---|
include.site | a logical value indicating whether the value of.Library.site should be included in the new set of library tree locations. Defaulting to TRUE, it is ignored when.libPaths is called without the new argument. |
Details
.Library
is a character string giving the location of the default library, the ‘library’ subdirectory of R_HOME.
.Library.site
is a (possibly empty) character vector giving the locations of the site libraries.
.libPaths
is used for getting or setting the library trees that Rknows about and hence uses when looking for packages (the library search path). If called with argument new
, by default, the library search path is set to the existing directories in unique(c(new, .Library.site, .Library))
and this is returned. If include.site
is FALSE
when the new
argument is set, .Library.site
is not added to the new library search path. If called without thenew
argument, a character vector with the currently active library trees is returned.
How paths in new
with a trailing slash are treated is OS-dependent. On a POSIX filesystem existing directories can usually be specified with a trailing slash. On Windows filepaths with a trailing slash (or backslash) are invalid and existing directories specified with a trailing slash may not be added to the library search path.
At startup, the library search path is initialized from the environment variables R_LIBS, R_LIBS_USER andR_LIBS_SITE, which if set should give lists of directories whereR library trees are rooted, colon-separated on Unix-alike systems and semicolon-separated on Windows. For the latter two, a value ofNULL
indicates an empty list of directories. (Note that as fromR 4.2.0, both are set by R start-up code if not already set or empty so can be interrogated from an R session to find their defaults: in earlier versions this was true only for R_LIBS_USER.)
First, .Library.site
is initialized from R_LIBS_SITE. If this is unset or empty, the ‘site-library’ subdirectory ofR_HOME is used. Only directories which exist at the time of initialization are retained. Then, .libPaths()
is called with the combination of the directories given by R_LIBS andR_LIBS_USER. By default R_LIBS is unset, and ifR_LIBS_USER is unset or empty, it is set to directory ‘R/R.version$platform-library/x.y’ of the home directory on Unix-alike systems (or ‘Library/R/m/x.y/library’ for CRAN macOS builds, withm [Sys.info](../../base/help/Sys.info.html)()["machine"]
) and ‘R/win-library/x.y’ subdirectory of LOCALAPPDATA on Windows, for R x.y.z.
Both R_LIBS_USER and R_LIBS_SITE feature possible expansion of specifiers for R-version-specific information as part of the startup process. The possible conversion specifiers all start with a ‘%’ and are followed by a single letter (use ‘%%’ to obtain ‘%’), with currently available conversion specifications as follows:
‘%V’
R version number including the patch level (e.g., ‘2.5.0’).
‘%v’
R version number excluding the patch level (e.g., ‘2.5’).
‘%p’
the platform for which R was built, the value of[R.version](../../base/help/R.version.html)$platform
.
‘%o’
the underlying operating system, the value of[R.version](../../base/help/R.version.html)$os
.
‘%a’
the architecture (CPU) R was built on/for, the value of [R.version](../../base/help/R.version.html)$arch
.
(See [version](../../base/help/version.html)
for details on R version information.) In addition, ‘%U’ and ‘%S’ expand to the R defaults for, respectively, R_LIBS_USER and R_LIBS_SITE.
Function .libPaths
always uses the values of .Library
and .Library.site
in the base namespace. .Library.site
can be set by the site in ‘Rprofile.site’, which should be followed by a call to .libPaths(.libPaths())
to make use of the updated value.
For consistency, the paths are always normalized by[normalizePath](../../base/help/normalizePath.html)(winslash = "/")
.
LOCALAPPDATA (usually C:\Users\username\AppData\Local
) on Windows is a hidden directory and may not be viewed by some software. It may be opened by shell.exec(Sys.getenv("LOCALAPPDATA"))
.
Value
A character vector of file paths.
References
Becker, R. A., Chambers, J. M. and Wilks, A. R. (1988)The New S Language. Wadsworth & Brooks/Cole.
See Also
[library](../../base/help/library.html)
Examples
.libPaths() # all library trees R knows about
[Package _base_ version 4.6.0 Index]