.libPaths()
[1] \"\\\\\\\\per-homedrive1.corp.riotinto.org/homedrive$/Tommy.O\'Dell/R/win-library/2.15\"
[2] \
Just set the environment variable R_LIBS
in Windows to something like
R_LIBS=C:/Program Files/R/R-2.15.2/library
Restart R.
This is bit late response to the question, but might be useful for others. I order to set up my own path (and remove one of the original ones) I have:
.libPaths()
inside R to check current library paths;R.home()
or Sys.getenv("R_HOME")
;
R-Home\R-3.2.2\etc\Rprofile.site
is read every time R kernel starts. Therefore, any modification will be persistent to every run of R.Rprofile.site
by adding the following,.libPaths(.libPaths()[2])
.libPaths("d:/tmp/R/win-library/3.2")
How it works?
Ctr+Shift+F10
)This will work every time now.
I have put the Sys.unsetenv("R_LIBS_USER")
command in a .Rprofile
file in my windows "own documents"
folder. Seems to help. My problem was that being in an active directory environment made R
upstart and package loading incredibly slow when connected via vpn.
If you want to do this at RProfile
file (@library/base/R/
), you can search the lines where R_LIBS_*
environment variables are set (for e.g. Sys.setenv(R_LIBS_SITE=....)
and Sys.setenv(R_LIBS_USER=.....)
)
You can also search the code .libPaths()
, which sets the library tree. So you can achieve your goal by a combination of commenting, unsetting and setting the R_LIBS
variables before the .libPaths()
call as you wish. For e.g. Something like:
Sys.unsetenv("R_LIBS")
Sys.unsetenv("R_LIBS_USER")
Sys.setenv(R_LIBS_SITE = "D:/R/libs/site")
Sys.setenv(R_LIBS_USER = "D:/R/libs/user")
Sys.setenv(R_LIBS = "D:/R/libs")
Use this function in .Rprofile
set_lib_paths <- function(lib_vec) {
lib_vec <- normalizePath(lib_vec, mustWork = TRUE)
shim_fun <- .libPaths
shim_env <- new.env(parent = environment(shim_fun))
shim_env$.Library <- character()
shim_env$.Library.site <- character()
environment(shim_fun) <- shim_env
shim_fun(lib_vec)
}
set_lib_paths("~/code/library") # where "~/code/library" is your package directory
Original Source: https://milesmcbain.xyz/hacking-r-library-paths/