I have attempted to install R and R studio on the local drive on my work computer as opposed to the organization network folder because anything that runs through the network is really slow. When installing, the destination path shows that it's my local C:drive. However, when I install a new package, the default path shown is my network drive and there is no option to change:
.libPaths() [1] "\\\\The library/path/I/don't/want" [2] "C:/Program Files/R/R-3.2.1/library"
I'm running windows 7 professional. How can I remove library path [1] and make path [2] my primary for all base packages and all new packages that I install?
R uses a single package library for each installed version of R on your machine. Fortunately it is easy to modify the path where R installs your packages. To do this, you simply call the function . libPaths() and specify the library location.
R packages are installed in a directory called library. The R function . libPaths() can be used to get the path to the library.
R packages are a collection of R functions, complied code and sample data. They are stored under a directory called "library" in the R environment. By default, R installs a set of packages during installation.
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
:
C:\R\Library
. Next I need to add this folder to the R_LIBS_USER
path:Start
--> Control Panel
--> User Accounts
--> Change my environmental variables
Environmental Variables
window pops up. If you see R_LIBS_USER
, highlight it and click Edit
. Otherwise click New
. Both actions open a window with fields for Variable
and Value
.R_LIBS_USER
was already there, and Value
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
).
See help(Startup)
and help(.libPaths)
as you have several possibilities where this may have gotten set. Among them are
R_LIBS_USER
.libPaths()
in .Rprofile
or Rprofile.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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With