Allan Engelhardt
2010-Jul-01 16:33 UTC
[R] How best to set library search path so user libraries come first
I want my local libraries to have priority over the system installed ones, which, as far as I can make out from help(".libPaths"), means they have to come first in that list (it doesn't actually_say_ so, but that seems to be the idea). We have R_LIBS_USER which looks made for specifying where I keep my own libraries. Unfortunately it comes last in .libPaths() [which appears to me to be a bug (1) if that means last in the search order and (2) because install.packages() defaults to the first element in .libPaths() while I think most users would (or rather: should) want to install packages in R_LIBS_USER most of the time]. My options for getting the order I expect seems to be (1) Add to ~/.Rprofile a construct along the lines of: .libPaths(c(Sys.getenv("R_LIBS_USER"), .libPaths())) (2) Add to ~/.Renviron something like: R_LIBS=${R_LIBS_USER}:${R_LIBS} Both of which works but both of which seems very hackish and maybe not robust :-( Is there a better way? Am I missing how R_LIBS* are intended to be used? Allan
Peter Ehlers
2010-Jul-02 10:37 UTC
[R] How best to set library search path so user libraries come first
On 2010-07-01 10:33, Allan Engelhardt wrote:> I want my local libraries to have priority over the system installed > ones, which, as far as I can make out from help(".libPaths"), means they > have to come first in that list (it doesn't actually_say_ so, but that > seems to be the idea). > > We have R_LIBS_USER which looks made for specifying where I keep my own > libraries. Unfortunately it comes last in .libPaths() [which appears to > me to be a bug (1) if that means last in the search order and (2) > because install.packages() defaults to the first element in .libPaths() > while I think most users would (or rather: should) want to install > packages in R_LIBS_USER most of the time]. > > My options for getting the order I expect seems to be > > (1) Add to ~/.Rprofile a construct along the lines of: > > .libPaths(c(Sys.getenv("R_LIBS_USER"), .libPaths())) > > (2) Add to ~/.Renviron something like: > > R_LIBS=${R_LIBS_USER}:${R_LIBS} > > Both of which works but both of which seems very hackish and maybe not > robust :-( Is there a better way? Am I missing how R_LIBS* are intended > to be used? > > AllanI just have R_LIBS=path.to.other.packages in .Renviron. The path to the base-R packages is then automatically appended as the second element of .libPaths(). (This is on Windows.) -Peter Ehlers
Maybe Matching Threads
- R CMD check --as-cran attempts to hide R_LIBS_USER but fails
- R CMD check --as-cran attempts to hide R_LIBS_USER but fails
- Debian Testing: ~/.Renviron seems to not being read (R_LIBS not set)
- Debian Testing: ~/.Renviron seems to not being read (R_LIBS not set)
- Windows 7 and .libPaths()