How do I change the default library path for R packages

r library path environment variable
r remove library path
r set libpaths permanently
how to change library path in r linux
update r library path
change library in r studio
how to set library for r
r installation path

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?

How do I change the default library path for R packages, See help(Startup) and help(.libPaths) as you have several possibilities where this may have gotten set. Among them are. setting  Using the default install.packages command can result in a series of frustrating messages like this: ’lib = “<myRlibrary>”’ is not writable. To address these issues, you will need to change the RStudio package library to a location for which you have access permissions. First, launch RStudio. Then, see where your default library currently lies.

Windows 7: 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 above, 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
  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 the value was a path to my desktop. I added to the path the folder that I created, separated by semicolon as mentioned above. C:\R\Library;C:\Users\Eric.Krantz\Desktop\R stuff\Packages. NOTE: I could have removed the path to the Desktop location and simply left C:\R\Library.

Change R default library path using .libPaths in , I generally try to keep all of my packages in one library, but if you want to add a library why not append the new library (which must already exist  Installations of R will tend to install libraries at C:/Program Files/R/R-X.X.X/library, which may not always be writable. The only way to effectively change this default resides outside of R in Microsoft Windows. In the Microsoft Control Panel, go to System and Security > System > Advanced system settings > Environment variables.

Facing the very same problem (avoiding the default path in a network) I came up to this solution with the hints given in other answers.

The solution is editing the Rprofile file to overwrite the variable R_LIBS_USER which by default points to the home directory.

Here the steps:

  1. Create the target destination folder for the libraries, e.g., ~\target.
  2. Find the Rprofile file. In my case it was at C:\Program Files\R\R-3.3.3\library\base\R\Rprofile.
  3. Edit the file and change the definition the variable R_LIBS_USER. In my case, I replaced the this line file.path(Sys.getenv("R_USER"), "R", with file.path("~\target", "R",.

The documentation that support this solution is here

Original file with:

 if(!nzchar(Sys.getenv("R_LIBS_USER")))
     Sys.setenv(R_LIBS_USER=
                file.path(Sys.getenv("R_USER"), "R",
                          "win-library",
                          paste(R.version$major,
                                sub("\\..*$", "", R.version$minor),
                                sep=".")
                          )) 

Modified file:

if(!nzchar(Sys.getenv("R_LIBS_USER")))
     Sys.setenv(R_LIBS_USER=
                file.path("~\target", "R",
                          "win-library",
                          paste(R.version$major,
                                sub("\\..*$", "", R.version$minor),
                                sep=".")
                          ))

Default library folder - General, I'm trying to change the default folder into which packages are installed. Currently it How do I change the default library path for R packages. r. Due to the new R 2.11 release, I want to implement Dirk's suggestion here. So for that I am asking - How can I (permanently) change R's library path? (The best solution would be one that can be run from within R)

Changing the default library folder path in R, Packages should now be saved to the new location. The PowerShell Method. Another method for achieving this in the command line is via  I am running R on a networked computer where I don't have write access to most locations on the C drive. However, my IT department decided to load the entire CRAN repository in the default library

Best practices for handling packages in R projects (Revolutions), 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 Rprofile, for example setting your CRAN mirror. However  .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)..libPaths is used for getting or setting the library trees that R knows about (and hence uses when looking for packages). If called with argument new, the library search path is set to the existing directories in unique(c(new, .Library.site, .Library)) and this is returned. If given no argument, a character vector with the

libPaths function, libPaths gets/sets the library trees within which packages are looked for. libPaths is used for getting or setting the library trees that R knows about (and hence The library search path is initialized at startup from the environment variable  All three strategies can be useful, but for most situations, we recommend the third. By default, R is configured for both common and user libraries. We often see organizations install frequently used packages in a common library while allowing users to install specific packages in their user library. User specific libraries

Comments
  • Thanks so much, I just set .libPaths("C:/Program Files/R/R-3.2.1/library") and now that's the only path that shows.
  • Interesting. I thought this added rather than overriding?
  • And it sure adds to an an existing .libPaths() on my Unix box.
  • In the help file it seemed to indicate to use the command to set the library path. Similar to setting the working directory. I could be wrong but that appears to be how it functioned for me. The first network path no longer appeared. The problem is when installing the base package I have to do it off network or it by default saves the program on my C:Drive as well as a copy on our network. I can't prevent the base library from being saved on the network, only any additional packages I install.
  • @DirkEddelbuettel I believe this function doesn't add to the existing .libPaths(). It takes the specified path (or vector of), appends the system lib path if it's not included, and sets. Any other paths that might have previously been added, including user-specific stuff from the initialization process, would need to be explicitly retained using .libPaths(c(mydir1,mydir2,.libPaths())) or some such.
  • I recently used the procedure on a machin with Win 7 and "~\target" did not work, I had to use "~/target". I have never understood properly why and when the use of "/" or "\" matters.