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
?
Best Answer
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.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:
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 usingpackrat
it works automatically so you don't need to specify thelib
norlib.loc
arguments when installing or loading packages.