views:

122

answers:

3

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?

A: 

Change permissions in the default library. Try .libPaths() to see folders where R saves packages by default. I'm using Arch Linux, and in my case it's:

> .libPaths()
[1] "/usr/lib/R/library"

But if you're running Ubuntu, you're probably going to get several folders. However, you need to run from terminal:

sudo chmod -R a+rw /usr/lib/R/library/

or from R:

system("sudo chmod -R a+rw /usr/lib/R/library/")

...for each folder, or you can do (from R):

for (i in 1:length(.libPaths())) {
     system(paste("sudo chmod -R a+rw", .libPaths()[i]))
}

...and change them all with one blow.

  • more info on shell command: chmod changes permissions of the files/folders, -R is for recursion, a+rw means: a ll can r ead + w rite, and then you point to the file/folder.
aL3xa
I do use ubuntu, I do have several folders returned by `.libPaths()`, I added permissions as you suggested but the first dir in the list is still under my home and every package I install goes there. Can I change that (delte this personal dir from R)?
David B
OK, I achieved that by something like `>.libPaths(.libPaths()[2:4])`
David B
Right... local R library was added to .libPaths(). I always set write permissions, cause it's a bit boring to run `sudo R` every time I want to install some packages.
aL3xa
+2  A: 

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
Neat one, definitely a better solution, though you've advertised your product(s)... =) Is `/usre/local...` a typo?
aL3xa
Well my advertising budget is small :) Typo fixed -- thanks.
Dirk Eddelbuettel
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
so how do I set back the permissions suggested by aL3xa (I already ran the loop)
David B
`sudo chmod -R 0755 /usr/lib/library/R` as 0755 (user write, group and others r) is the default for directories.
Dirk Eddelbuettel
Sorry for my "solution". I'm the one and only user, so it's "safe" to change permissions in my case.
aL3xa
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 writableWould you like to create a personal library'~/R/i486-pc-linux-gnu-library/2.11'to install packages into? (y/n) `
David B
Please consider posting the question on r-sig-debian.
Dirk Eddelbuettel
A: 

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
Or add yourself to group `staff` as I wrote and you don't need `sudo` to run as root.
Dirk Eddelbuettel