[Rd] Preventing $R_HOME/site-library/ via R_LIBS_SITE=":" (no other way?)
Henrik Bengtsson
hb at biostat.ucsf.edu
Fri Apr 25 20:49:23 CEST 2014
(As a non-root/non-admin), I've just tried to figure out how to
prevent a default $R_HOME/site-library/ to be added to the library
path. The solution I found was to environment variable R_LIBS_SITE to
":" (preferably in ~/.Renviron). Note that setting R_LIBS_SITE to en
empty string will cause it to fall back to using
$R_HOME/site-library/. This "hack" is based on the following in
help(".Library.site"):
.Library.site is a (possibly empty) character vector giving the
locations of the site libraries, by default the ‘site-library’
subdirectory of R_HOME (which may not exist).
[...]
.Library.site can be set via the environment variable R_LIBS_SITE (as
a non-empty colon-separated list of library trees).
It turns out that any dummy string would work (e.g.
R_LIBS_SITE=non-existing-directory), but using the OS's path separator
is at least according to the docs.
TROUBLESHOOTING/PATCHING:
I don't see an obvious elegant fix to this in R, but I believe the
issue is that the system/global Rprofile
(src\library\profile\Common.R) does:
Sys.setenv(R_LIBS_SITE =
.expand_R_libs_env_var(Sys.getenv("R_LIBS_SITE")))
Here this information on whether R_LIBS_SITE is unset or empty is
lost. Sys.getenv("R_LIBS_SITE", NA_character_) would distinguish the
two cases. However, NA_character_ is coerced to "NA" in
Sys.setenv(R_LIBS_SITE = ...), which means a site library cannot be
"NA". I assume my above "hack" could be done as:
local({
libs <- Sys.getenv("R_LIBS_SITE", NA_character_)
libs <- if (is.na(libs)) "" else if (libs == "") .Platform$path.sep else libs
Sys.setenv(R_LIBS_SITE = .expand_R_libs_env_var(libs))
})
Not elegant, but it should work. If not added, may I propose the
following patch to the docs:
>svn diff src\library\base\man\libPaths.Rd
Index: src/library/base/man/libPaths.Rd
===================================================================
--- src/library/base/man/libPaths.Rd (revision 65492)
+++ src/library/base/man/libPaths.Rd (working copy)
@@ -63,6 +63,8 @@
\code{.Library.site} can be set via the environment variable
\env{R_LIBS_SITE} (as a non-empty colon-separated list of library trees).
+ To prevent the default \file{site-library} subdirectory of
+ \env{R_HOME} to be used, one can set \env{R_LIBS_SITE} to \code{":"}.
#endif
#ifdef windows
The library search path is initialized at startup from the environment
@@ -77,6 +79,8 @@
\code{.Library.site} can be set via the environment variable
\env{R_LIBS_SITE} (as a non-empty semicolon-separated list of library trees).
+ To prevent the default \file{site-library} subdirectory of
+ \env{R_HOME} to be used, one can set \env{R_LIBS_SITE} to \code{";"}.
#endif
Both \env{R_LIBS_USER} and \env{R_LIBS_SITE} feature possible
My $.02 - may save someone else 30 mins.
More information about the R-devel
mailing list