1

I am familiar with Unix as an operating system, but not in the general logic of how developers decide to organize application library locations.

Take R, for example. Installing R on ubuntu can be done with apt-get. You'll get an installation into the directory:

/usr/local/R/lib/site-library         --> All R packages go here.
/usr/lib/R/library                    --> R packages go here.

Both of these directories are by default not writable. So why does an R installation default to install there?

I've had numerous issues installing R packages into the "default" directory (which I guess is /usr/lib/R/library?), so I've had to install them into a local directory at ~/R/x86_64_pc-linux_gnu-library/3.2.

My question is: how do I get rid of ALL "default" libraries and ONLY use my local library directory? Not only removing old default libraries, but to let R know that my new default library is at ~/R/x86_64_pc-linux_gnu-library/3.2?

  • 1
    The directories should be writeable by root, and you should be running apt-get with root permissions (using sudo). It's designed this way so that non-privileged users can't mess with system-wide applications. – steeldriver Dec 7 '15 at 22:19
  • So in my initial install of the R language, I should have used sudo? I have chmod-ed it up so many times, but nothing changes the fate of the dreaded "Permission denied" error. I have deleted R entirely and am about to do a fresh install, but I worry I will have the same issue. Should I install the R tree locally and remove all doubt? – areyoujokingme Dec 8 '15 at 19:01
  • 1
    I would suggest just using "personal libraries" and using the repos to keep track of the patches in your base R install. Are there any packages in the default install that step on something you need? If you do an install.packages() as a non-root user it should give you a message about not having write access and ask if you want to create "personal libraries" in your home dir which should be good for anything that your user does. – Eddie Dunn Dec 13 '15 at 0:25
1

Both of these directories [/usr/local/R/lib/site-library and /usr/lib/R/library] are by default not writable. So why does an R installation default to install there?

I've had numerous issues installing R packages into the "default" directory (which I guess is /usr/lib/R/library?), so I've had to install them into a local directory at ~/R/x86_64_pc-linux_gnu-library/3.2.

The default R packages (e.g., base) are installed in these system libraries as these are available to all users on that machine.

Although they are not writable by a non-root user, this is by design. A user would install their additional packages to a personal library instead.

You can see the default location for this personal library by running Sys.getenv('R_LIBS_USER') in your R console.

The .libPaths() command lets you view the current set of library search paths, as well as add additional paths.

My question is: how do I get rid of ALL "default" libraries and ONLY use my local library directory? Not only removing old default libraries, but to let R know that my new default library is at ~/R/x86_64_pc-linux_gnu-library/3.2?

You don't want to "get rid of" those default libraries as they contain the default set of R packages. These are required for R to work correctly.

R already knows about the default personal library location (see .libPaths()).

However, you can specify where you want to install package to and load them from by specifying a library location:

install.packages('packageName', lib = Sys.getenv('R_LIBS_USER'))
library('packageName', lib.loc = Sys.getenv('R_LIBS_USER'))

To more easily control R package versions (which is especially important for reproducible research), I recommend the packrat package. It can be used to configure a personal library for each of your projects, allowing each project to use its own set of packages (i.e., different versions). When using packrat it works automatically so you don't need to specify the lib nor lib.loc arguments when installing or loading packages.

2

If you want to not use the packaged version of R, then you need to install your own version to a private directory where you will use it from.

It's also possible to create Ubuntu packages of additional R libraries, so that they are installed to the system, if that's what you want.

  • I like your suggestion about installing R in private directory. What does your second paragraph mean, though? To "create Ubuntu packages of additional R libraries"? – areyoujokingme Dec 8 '15 at 19:03
  • It means to build .deb packages, which install those libraries into the system directory. You can also distribute open source libraries as .deb packages via PPA on launchpad.net so that others may more easily install the libraries too. – dobey Dec 8 '15 at 22:49

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.