setLibPaths {Require} | R Documentation |
Set .libPaths
Description
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
. Currently, the default is to make this new
.libPaths()
"sticky", meaning it becomes associated with the current
directory even through a restart of R. It does this by adding and/updating
the ‘.Rprofile’ file in the current directory. If this current directory
is a project, then the project will have the new .libPaths()
associated
with it, even through an R restart.
Usage
setLibPaths(
libPaths,
standAlone = TRUE,
updateRprofile = getOption("Require.updateRprofile", FALSE),
exact = FALSE,
verbose = getOption("Require.verbose")
)
Arguments
libPaths |
A new path to append to, or replace all existing user
components of |
standAlone |
Logical. If |
updateRprofile |
Logical or Character string. If |
exact |
Logical. This function will automatically append the R version
number to the |
verbose |
Numeric or logical indicating how verbose should the function
be. If -1 or -2, then as little verbosity as possible. If 0 or FALSE,
then minimal outputs; if |
Details
This details of this code were 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.
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.
Examples
## Not run:
if (Require:::.runLongExamples()) {
opts <- Require:::.setupExample()
origDir <- setwd(tempdir())
td <- tempdir()
setLibPaths(td) # set a new R package library locally
setLibPaths() # reset it to original
setwd(origDir)
# Using standAlone = FALSE means that newly installed packages
# will be installed
# in the new package library, but loading packages can come
# from any of the ones listed in .libPaths()
# will have 2 or more paths
otherLib <- file.path(td, "newProjectLib")
setLibPaths(otherLib, standAlone = FALSE)
# Can restart R, and changes will stay
# remove the custom .libPaths()
setLibPaths() # reset to previous; remove from .Rprofile
# because libPath arg is empty
Require:::.cleanup(opts)
unlink(otherLib, recursive = TRUE)
}
## End(Not run)