Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How do you change library location in R? [duplicate]

Tags:

installation

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)

like image 669
Tal Galili Avatar asked Apr 23 '10 12:04

Tal Galili


People also ask

How do I change the default installation directory in R?

The way to change a package library location is to manually set it on a startup file i.e. folder) or project-level (located at the current working directory). ✏ For more information about R startup files, you can read the following support article.

What happens if you install a package twice in R?

It shouldn't be an issue unless you install a package as an admin user, and again as a normal user. Then you will have a version in two different locations on your system. That could lead to issues when upgrading, or confusion as to which version is loaded.


2 Answers

You can edit Rprofile in the base library (in 'C:/Program Files/R.Files/library/base/R' by default) to include code to be run on startup. Append

########        User code        ######## .libPaths('C:/my/dir') 

to Rprofile using any text editor (like Notepad) to cause R to add 'C:/my/dir' to the list of libraries it knows about.

(Notepad can't save to Program Files, so save your edited Rprofile somewhere else and then copy it in using Windows Explorer.)

like image 132
Gred Avatar answered Sep 22 '22 06:09

Gred


I've used this successfully inside R script:

library("reshape2",lib.loc="/path/to/R-packages/") 

useful if for whatever reason libraries are in more than one place.

like image 22
IsC Avatar answered Sep 23 '22 06:09

IsC