Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to change and remove default library location?

Tags:

r

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 location on the C drive. I would strongly prefer to manage my packages on my own, and have a location on my networked drive I can install to, but I am trying to get R to ignore and forget the C drive location entirely.

I have tried creating an .Rprofile file to set the library location, but no matter what I do, .libPaths() does not seem to forget the default location. I have tried the following:

.Library <- file.path("N:/My Documents/R/win-library/3.2")
.Library.site <- file.path("N:/My Documents/R/win-library/3.2")
.lib.loc <- file.path("N:/My Documents/R/win-library/3.2")
.libPaths(.libPaths())

Where the path on the N drive is the new location I want to be the only library path. But when I restart R and run .libPaths(), I still see this:

[1] "\\\\fileu/users$/username/My Documents/R/win-library/3.2"
[2] "C:/Program Files/R/R-3.2.4/library"

(On a side note, I'm trying to switch from the symbolic '\fileu' reference to a reference to the N drive.)

I know there have been similar questions asked on this in the past (e.g., here), but the particular problem I'm having is that it's not forgetting the C drive location. I can't seem to erase that at all. Any help would be greatly appreciated!

like image 240
Jeff Hughes Avatar asked Apr 26 '16 18:04

Jeff Hughes


People also ask

How do I change the default library path in R?

To set environment variable R_LIBS_USER in Windows, go to the Control Panel (System Properties -> Advanced system properties -> Environment Variables -> User Variables) to a desired value (the path to your library folder), e.g.

What is library command in R?

library(help = somename) computes basic information about the package somename, and returns this in an object of class "packageInfo" . (The structure of this class may change in future versions.) When used with the default value ( NULL ) for lib. loc , the attached packages are searched before the libraries.

Where are R packages installed?

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


1 Answers

Here be dragons.

assign(".lib.loc", "\your\preferred\library", envir = environment(.libPaths))
like image 152
Andrie Avatar answered Oct 07 '22 20:10

Andrie