How do I change the default library path for R packages
Solution 1:
Windows 7/10: If your C:\Program Files
(or wherever R is installed) is blocked for writing, as mine is, then you'll get frustrated editing RProfile.site
(as I did). As specified in the accepted answer, I updated R_LIBS_USER
and it worked. However, even after reading the fine manual several times and extensive searching, it took me several hours to do this. In the spirit of saving someone else time...
Let's assume you want your packages to reside in C:\R\Library
:
- Create the folder
C:\R\Library
. Next I need to add this folder to theR_LIBS_USER
path: - Click
Start
-->Control Panel
-->User Accounts
-->Change my environmental variables
- The
Environmental Variables
window pops up. If you seeR_LIBS_USER
, highlight it and clickEdit
. Otherwise clickNew
. Both actions open a window with fields forVariable
andValue
. - In my case,
R_LIBS_USER
was already there, andValue
was a path to my desktop. I added to the path the folder that I created, separated by semicolon.C:\R\Library;C:\Users\Eric.Krantz\Desktop\R stuff\Packages
.
(NOTE: In the last step, I could have removed the path to the Desktop location and simply left C:\R\Library
).
Solution 2:
See help(Startup)
and help(.libPaths)
as you have several possibilities where this may have gotten set. Among them are
- setting
R_LIBS_USER
- assigning
.libPaths()
in.Rprofile
orRprofile.site
and more.
In this particular case you need to go backwards and unset whereever \\\\The library/path/I/don't/want
is set.
To otherwise ignore it you need to override it use explicitly i.e. via
library("somePackage", lib.loc=.libPaths()[-1])
when loading a package.