[R] How best to set library search path so user libraries come first

Peter Ehlers ehlers at ucalgary.ca
Fri Jul 2 12:37:07 CEST 2010


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?
>
> Allan


I 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



More information about the R-help mailing list