6

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.

Trees4theForest
  • 1,267
  • 2
  • 18
  • 48

2 Answers2

7

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.

Tommy
  • 39,997
  • 12
  • 90
  • 85
  • Good to know. Yeah - thats part of the trick... but not insurmountable. Any recommendation on what directory to choose (and stick to) and how to ensure R always uses it? – Trees4theForest Dec 18 '11 at 08:28
  • Ok - I see the how, but not sum much the why. And I'm coming up blank on the help files... For example, what is the difference between /library/ and /site-library/ ? – Trees4theForest Dec 18 '11 at 08:50
  • 1
    That's a policy decision we once made a few years ago which I explained a few times on r-sig-debian and here; look for various answers related to .libPath, help(Startup) and packages on Ubuntu/Debian. – Dirk Eddelbuettel Dec 18 '11 at 16:16
  • Thanks @DirkEddelbuettel - I've re-read help(Startup) several times, and like so many of the help files in R it is exactingly precise, comprehensive, and detailed, thus making it fairly inaccessible to mere mortals like myself. But I think I pieced together an understanding - which hopefully help others. Please review, and let me know if I've suggested anything dangerous or flat out wrong. -Cheers! – Trees4theForest Dec 19 '11 at 06:02
4

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.

Trees4theForest
  • 1,267
  • 2
  • 18
  • 48
  • 1
    Do **not** write below `/usr`; only `dpkg`, `apt`, ... should access those files. For user-level files, use `/usr/local` (or `/opt`). – Dirk Eddelbuettel Dec 19 '11 at 13:57
  • This is in reference to copying folders ya? Gotcha. So before I update my answer, are the files in `/usr/lib/R/site-library/` ONLY packages installed by apt? And a vanilla R default install places packages installed using `install.packages()` in `usr/local/lib/R/site-packages`? For bonus points, if I install via apt, then update via `update.packages()` where do the files go? Overwriting `user/lib/R/site-library` or placed in `usr/local/lib/R/site-library/` -- and does `sudo` make a difference? If this is all spelled out somewhere, please redirect me. My searches have come up empty... Thanks – Trees4theForest Dec 20 '11 at 03:13
  • 1
    Anything from Ubuntu/Debian installed via apt, dpkg, ... : `/usr/`. Anything you do (eg via R's `install.packages()`): `/usr/local`. That is a general rule for all applications, not just R. Do *not* manually mess below `/usr`, you may come to regret it. If you have questions, ask on the `r-sig-debian` list. – Dirk Eddelbuettel Dec 20 '11 at 03:15