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)



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.


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.


This code was modified from A different, likely non-approved by CRAN approach that also works is here:


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 }