Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How do I change the default library path for R packages

Tags:

r

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?

like image 912
user3594490 Avatar asked Jul 29 '15 18:07

user3594490


People also ask

How do I change the package installation path in R?

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.

Where does R install packages by default?

R packages are installed in a directory called library. The R function . libPaths() can be used to get the path to the library.

Where are R packages stored locally?

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.


2 Answers

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:

  1. Create the folder C:\R\Library. Next I need to add this folder to the R_LIBS_USER path:
  2. Click Start --> Control Panel --> User Accounts --> Change my environmental variables
  3. The 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.
  4. In my case, 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).

like image 195
Eric Krantz Avatar answered Sep 22 '22 04:09

Eric Krantz


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 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.

like image 25
Dirk Eddelbuettel Avatar answered Sep 23 '22 04:09

Dirk Eddelbuettel