Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

R: combining mutiple library locations with most up-to-date packages

Tags:

r

packages

Question: How do I move all of the most up-to-date R packages into one simple location that R (and everything else) will use from now and forever for my packages?

I have been playing around with R on Ubuntu 10.04 using variously RGedit, RCmdr, R shell, and RStudio. Meanwhile, I have installed packages, updated packages, and re-updated packages via apt, synaptic, install.packages(), etc... which apparently means these packages get placed everywhere, and (with the occasional sudo tossed in) with different permissions.

Currently I have different versions of different (and repeated) packages in:

/home/me/R/i486-pc-linux-gnu-library/2.10
/home/me/R/i486-pc-linux-gnu-library/2.14
/home/me/R/i486-pc-linux-gnu-library/
/usr/local/lib/R/site-library               
/usr/lib/R/site-library                     
/usr/lib/R/library 

First - I'm a single user, on a single machine - I don't want multiple library locations, I just want it to work.

Second - I am on an extremely slow connection, and can't keep just downloading packages repeatedly.

So - is there an easy way to merge all these library locations into one simple location? Can I just copy the folders over?

How do I set it in concrete that this is and always will be where anything R related looks for and updates packages?

This is maddening.

Thanks for your help.

like image 756
Trees4theForest Avatar asked Dec 18 '11 08:12

Trees4theForest


2 Answers

Yes, it should almost work to just copy the folders over. But pre-2.14 packages WITHOUT a NAMESPACE file probably won't work in R 2.14 where all packages must have a namespace...

And you'd want to manually ensure you only copy the latest version of each package if you have multiple versions...

If you type .libPaths(), it will tell you where R looks for packages. The first in the list is where new packages are typically installed. I suspect that .libPaths() might return different things from RStudio vs. Rcmd etc.

like image 153
Tommy Avatar answered Nov 09 '22 22:11

Tommy


After piecing together various bits of info here goes: A complete moron's guide to the R packages directory organization:

NB1 - this is my experience with Ubuntu - your mileage may vary NB2 - I'm a single user on a single machine, and I like things simple.

Ubuntu puts anything installed via apt, or synaptic in:

/usr/lib/R/site-library                     
/usr/lib/R/library

directories. The default vanilla R install will try install packages here:

/usr/local/lib/R/site-library

Since these are system directories the user does not have write privileges to, depending on what method you are interacting with R you might be prompted with a friendly - "Hey buddy - we can't write there, you want us to put your packages in your home directory?" which seems innocent and reasonable enough... assuming you never change your GUI, or your working environment. If you do, the new GUI / environment might not be looking in the directory where the packages were placed, so won't find them. (Most interfaces have a way for you to point where your personal library of packages is, but who wants to muck about in config files?)

What seems to be the best practice for me (and feel free to correct me if I'm wrong) with a default install setup on Ubuntu, is to do any package management from a basic R shell as sudo: > sudo R and from there do your install.packages() voodoo. This seems to put packages in the usr/local/lib/R/site-library directory.

At the same time, update.packages() will update the files in /usr/lib/R/site-library and usr/lib/R/library directories, as well as usr/local/lib/R/site-library

(As for usr/lib/R/ division, it looks like /library/ has the core packages, while /site-library/ holds anything added, assuming they were installed by apt...)

Any packages previously installed and in the wrong place can be moved to the /usr/local/lib/R/site-library directory (assuming you are sudoing it) just by moving the directories (thanks @Tommy), but as usr/lib/R/ is controlled by apt - best not add or subtract anything from there...

Whew. Anyway - simple enough, and in simple language. Thanks everyone for the help.

like image 27
3 revs Avatar answered Nov 09 '22 22:11

3 revs