libPaths {base}R Documentation

Search Paths for Packages


.libPaths gets/sets the library trees within which packages are looked for.


.libPaths(new, = TRUE)




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.

a logical value indicating whether the value of 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.


.Library is a character string giving the location of the default library, the ‘library’ subdirectory of R_HOME. is a (possibly empty) character vector giving the locations of the site libraries.

.libPaths is used for getting or setting the library trees that R knows 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)) and this is returned. If is FALSE when the new argument is set, is not added to the new library search path. If called without the new 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 and R_LIBS_SITE, which if set should give lists of directories where R library trees are rooted, colon-separated on Unix-alike systems and semicolon-separated on Windows. For the latter two, a value of NULL indicates an empty list of directories. (Note that as from R 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, is initialized from R_LIBS_SITE. If this is unset or empty, the ‘site-library’ subdirectory of R_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 and R_LIBS_USER. By default R_LIBS is unset, and if R_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, with m["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:


R version number including the patch level (e.g., ‘⁠2.5.0⁠’).


R version number excluding the patch level (e.g., ‘⁠2.5⁠’).


the platform for which R was built, the value of R.version$platform.


the underlying operating system, the value of R.version$os.


the architecture (CPU) R was built on/for, the value of R.version$arch.

(See version 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 in the base namespace. can be set by the site in ‘’, 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(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")).


A character vector of file paths.


Becker, R. A., Chambers, J. M. and Wilks, A. R. (1988) The New S Language. Wadsworth & Brooks/Cole.

See Also



.libPaths()                 # all library trees R knows about

[Package base version 4.4.0 Index]