tags:

views:

235

answers:

3

preface: i'm an os x user coming to linux, so excuse my ignorance in advance

i've installed R using synaptic and now i'm trying to install packages.

i open R then try install.packages("some package")

system tries to default to /site-library, then tell's me it's not writable

then asks about making a personal library?

should I just make site-library writable? or is there something more to this

Can anyone beat Dirk to this answer?

+2  A: 

The directory /usr/share/local/lib/R is the default location; the directory is has ownership root:staff by default. If you add yourself to group staff (easiest: by editing /etc/group and /etc/gshadow) you can write there and you do not need sudo powers for the installation of packages. That is what I do.

Alternatively, do apt-get install littler and copy the example file /usr/share/doc/littler/examples/install.r to /usr/local/bin and chmod 755 it. The you can just do sudo install.r lattice ggplot2 to take two popular examples.

BTW Ubuntu 8.1 does not exist as a version. Maybe you meant 8.10? Consider upgrading to 9.10 ...

Edit: Also have a look at this recent SO question.

Dirk Eddelbuettel
absolutely meant 8.10, though i'm upgrading it to 9.10 now as per the advice of another friend. thanks for the tip and i'll give it a shot, thanks
Dan
Even easier way to add a user to a group: `adduser dan staff`.
Jukka Matilainen
last check, is this a better way to add myself to group staff http://www.cyberciti.biz/faq/howto-linux-add-user-to-group/
Dan
A: 

If you are the only user who needs those packages, then the easiest and neatest way is to let R create a personal library for you. That way you don't need to mess with the system directories managed by the package management system.

Another way to install some packages in Ubuntu is to look for Ubuntu packages with names like r-cran-*. This way you do not have to worry about dependencies, the packages become available to all users, and updates are taken care of by the Ubuntu package management system. But only a small proportion of CRAN packages are available this way and you may not get the latest version.

Jyotirmoy Bhattacharya
A: 

Well, I prefer to install packages into local R folder ~/R/, but it's just a matter of an individual preference... you can also grant yourself a write permission to default library, it doesn't make any difference.

Be sure to add up-to-date packages. Those packages available in default repos are quite old. R v.2.9.0 is available by default in 9.10, while v.2.10.1 is now available. So stay up-to-date, add this line to file /etc/apt/sources.list (replace <text> with CRAN server address, you can find server addresses on www.r-project.org > CRAN > Linux > Ubuntu):

deb http://&lt;my.favorite.cran.mirror&gt;/bin/linux/ubuntu karmic/

then run this line in terminal:

gpg --keyserver subkeys.pgp.net --recv-key E2A11821 && gpg -a --export E2A11821 | sudo apt-key add -

and if keys are imported properly, run:

sudo apt-get install r-base-core

or if you already installed R, run:

sudo apt-get update && sudo apt-get upgrade

you should also check for alias functions (try man alias in terminal) to automatize repetitive tasks... feel comfortable in terminal, Synaptic is indeed a good tool, but most Linux users prefer command-line approach for a good reason - it's highly customizable =)

I recommend that you stick with one server (be advised when choosing the default server - I prefer UCLA's server, Berkeley works just fine, Main server is usually busy as hell... so there...)

Alternatively, you can add default CRAN server to .First() function:

# replace '<server address>'

.First() <- function() {
options("repos" = c(CRAN = "<my.favorite.cran.mirror>"))
}

now you can just type:

> install.packages('<somepackage>')

and you'll lose the boring Tcl/Tk serverlist window! Oh, what a relief!

Welcome to Ubuntu!
Cheers, mate!

aL3xa
that was a great answer, sorry dirk already got the check, thanks!
Dan
it's OK... it's just so hard to answer promptly and as precise as Dirk! All the best!
aL3xa
It is a slightly different answer. The Ubuntu repo at CRAN is mostly about R itself, not packages. The `options("repos")` bit I did fail to mention explicitly, but littler`s `install.r` does just that. And lastly, I do not think ~/R is good practice (apart from purely private modules), but each to his or her own.
Dirk Eddelbuettel
Hi Dirk! I took a glance at `install.r` source, and the default CRAN server is `http://cran.us.r-project.org`. Of course, that can be edited at some point forward... BTW I found a typo in code (nothing serious):`cat("Usage: installr.r pkg1 [pkg2 pkg3 ...]\n")` should be `install.r`... as I said, nothing serious...Would you, please, explain merits of using default lib.loc, and not creating a personal ones in ~/ folder? What are the downsides of personal library approach? Thanks!
aL3xa