This will set the .libPaths() by either adding a new path to it if standAlone = FALSE, or will concatenate c(libPath, tail(.libPaths(), 1)) if standAlone = TRUE.

setLibPaths(libPaths, standAlone = TRUE)

Arguments

libPaths A new path to append to, or replace all existing user components of .libPath() Logical. If TRUE, all packages will be installed to and loaded from the libPaths only. If FALSE, then libPath will be prepended to .libPaths() during the Require call, resulting in shared packages, i.e., it will include the user's default package folder(s). This can be create dramatically faster installs if the user has a substantial number of the packages already in their personal library. Default FALSE to minimize package installing.

Value

The main point of this function is to set .libPaths(), which will be changed as a side effect of this function. As when setting options, this will return the previous state of .libPaths() allowing the user to reset easily.

Details

This code was modified from https://github.com/milesmcbain. A different, likely non-approved by CRAN approach that also works is here: https://stackoverflow.com/a/36873741/3890027.

Examples

if (FALSE) {
orig <- setLibPaths("~/newProjectLib") # will only have 2 paths,
# this and the last one in .libPaths()
.libPaths() # see the 2 paths
setLibPaths(orig) # reset
.libPaths() # see the 2 original paths back

# will have 2 or more paths
setLibPaths("~/newProjectLib", standAlone = FALSE) # will have 2 or more paths

}