27

I have a few R packages installed under ~/R/i486-pc-linux-gnu-library/2.11.

I would like to make them, and any other R package I install from now on, available to all R users. I don't mind re-installing the packages I already have in a neutral place (they are just a few). So how do I do that?

David B
  • 29,258
  • 50
  • 133
  • 186

3 Answers3

32

aL3xa gives (IMHO) bad advice. Do not mess with /usr which is handled by the package management system. Instead, use the facility provided by /usr/local/lib/R/site-library.

That latter directory is already searched by default. All you need to do is to add yourself to group staff as that group has write-rights there -- try adduser yourid staff where yourid is your user name on the system. Afterwards you should be able to install there without problems.

Another thing you may like on Ubuntu is apt-get install littler and then use the install.r and upgrade.r helper scripts from the examples directory. I use them all the time.

Dirk Eddelbuettel
  • 360,940
  • 56
  • 644
  • 725
  • Neat one, definitely a better solution, though you've advertised your product(s)... =) Is `/usre/local...` a typo? – aL3xa Aug 15 '10 at 14:40
  • Well my advertising budget is small :) Typo fixed -- thanks. – Dirk Eddelbuettel Aug 15 '10 at 15:07
  • One more question: `staff` group is another of your products (since you maintain Debian/Ubuntu packages)? It's available only on those packages? If so, I'm migrating back to Ubuntu... maybe! =) – aL3xa Aug 15 '10 at 16:37
  • so how do I set back the permissions suggested by aL3xa (I already ran the loop) – David B Aug 15 '10 at 16:39
  • `sudo chmod -R 0755 /usr/lib/library/R` as 0755 (user write, group and others r) is the default for directories. – Dirk Eddelbuettel Aug 15 '10 at 17:01
  • Sorry for my "solution". I'm the one and only user, so it's "safe" to change permissions in my case. – aL3xa Aug 16 '10 at 01:25
  • I added my user to `staff` but when trying to install a package from R I still get `> install.packages("getopt") Warning in install.packages("getopt") : argument 'lib' is missing: using '/usr/local/lib/R/site-library' Warning in install.packages("getopt") : 'lib = "/usr/local/lib/R/site-library"' is not writable Would you like to create a personal library '~/R/i486-pc-linux-gnu-library/2.11' to install packages into? (y/n) ` – David B Sep 05 '10 at 07:42
  • Please consider posting the question on r-sig-debian. – Dirk Eddelbuettel Sep 05 '10 at 12:17
  • Where can I find more info about install.r and upgrade.r of the littler program? thanks – Janvb Dec 23 '11 at 16:18
  • They are (really short) examples in the littler package, just as it says in the third paragraph of my answer above. – Dirk Eddelbuettel Dec 23 '11 at 16:21
  • 2
    This answer was very helpful, but is missing a few details. After adding yourself to the `staff` group, you need to log out and back in for it to have effect (hence David B's error). But how to tell R to install in `/usr/local/...`? I found one method: `install.packages('foo', '/usr/local/lib/R/site-library')`. – Serrano Mar 12 '15 at 12:00
  • Yes, logging in and out (ie creating a new session for you) is required. The location is normally the default on Debian-based systems; littler which has been mentioned here also sets it in `install.r` and now also `install2.r`. – Dirk Eddelbuettel Mar 12 '15 at 12:20
  • After having searched I guess this is the question that matches mine to the closest, hence not creating a new question. Request @DirkEddelbuettel to kindly enlighten us, in which situation is package installed in each of these directories: `[1] "/home/rstudio/R/x86_64-pc-linux-gnu-library/3.4" "/usr/local/lib/R/site-library" [3] "/usr/lib/R/site-library" "/usr/lib/R/library" `. It has left be floundering for answers when I see 128 packages are lying in the first directory, 90 in the second, 1 in the third and 15 in the fourth. – Lazarus Thurston Feb 01 '19 at 13:21
  • @Sanjay: This is a eight+ years old question and answer, but I answered similar questions many times over. Keep looking for other answers In short: unless something else is specified _the first_ position in `.libPaths()` is used. – Dirk Eddelbuettel Feb 01 '19 at 13:31
  • Did a little bit more searches and the situation appears murkier than earlier. I chanced upon your excellent advice here https://stat.ethz.ch/pipermail/r-sig-debian/2018-May/002833.html and now am thinking if I made a mistake to leap forward to instal 3.5.2 on my ubuntu server. Would you still go by your advice of avoiding the jump, or has the situation changed and R 3.5.2 on ubuntu 16 installation is now well documented and robust? – Lazarus Thurston Feb 01 '19 at 16:58
  • @Sanjay May I ask you to stop this subthread here? It really is not the right place. Post on r-sig-debian and describe your situation and concerns. FWIW I run the current R 3.5.2 (via the CRAN-mirrored apt repository) on several current Ubuntu 18.10 machines. – Dirk Eddelbuettel Feb 01 '19 at 17:36
8

aL3xa answer is wrong; you shouldn't expose those directories to write for all users.
Run R as a root (probably using sudo R) and then install packages as usual -- they will be placed in a global library and will be available for all users.

mbq
  • 18,510
  • 6
  • 49
  • 72
2

In your case, the easiest way would be to install the packages as root (or as administrator in case of Windows), they'll be available for every user on that machine.

Feri
  • 230
  • 4
  • 11