Notes for Installing R Libraries
Some notes for loading libraries, including adding 'personal' library site to R lookup.
Setting up Custom Library Location for R packages
If you want or need to download and install packages, and don't have root access, you will need to install the R library/package in your personal library path.
So, create a directory to store 'installed' R libraries.
Then, in your home directory, you should have a file call .Renviron
In the .Renviron file, you should have the a single line:
R_LIBS=PATH_TO_YOUR_R_LIB_LOCATION
The .Renviron is found 'automatically' during the search.
Setting up Custom Library Location for R packages
On the other hand, you can specify the .Renviron file to be used via a environment variable. This is useful if you work on more than 1 type of *NIX environment (I'm working on CentOS4, CentOS%, Solaris8, and Solaris10).
In this case, you will need a 'custom' library site, I think, for each OS system. Mostly, as the R packages can include C++ or Fortran components. In this case, I'd create a file for each Environment. So, .RenvironCentOS4 and .RenvironSolaris10, for example. In each one, place the 'os' specific R library path.
Then, in you .cshrc script add these lines:
set ryantemp = `echo ``uname -s`
if (${ryantemp} == "SunOS") then
set ryantemp = `echo ``uname -r`;
if (${ryantemp} == "5.10") then
setenv R_ENVIRON
${HOME}/.RenvironSolaris10
endif
else
if (${ryantemp} == "Linux") then
if (`cat /etc/redhat-release | cut -d ' '
-f1` == "CentOS") then
if (`cat
/etc/redhat-release | cut -d ' ' -f3 | cut -c1` == '4') then
setenv R_ENVIRON ${HOME}/.RenvironCentOS4
endif
endif
endif
endif
See HERE to figure out something similar for bash.
Loading Custom Library Location for R packages
Regardless of which of the above options you go with, eventually, you will have your 'local' R library path defined. Now, the idea is to download and install your package of choice.
The command is:
install.packages("PackageName", "Your_Local_Library", destdir="Where_To_Store_The_Download", dependencies=TRUE)
The install will ask you for the CRAN mirror (I'm assuming the package is at CRAN. If not, look roughly at page 15 of the R Admin manual for details of alternate package loading commands!). The PackageName is the short name the package is known by. The Your_Local_Library is the full path name of your 'local' R library. dependencies can be either TRUE (in which case any required or recommended R libraries are also downloaded and installed) or FALSE, in which case only PackageName is installed (or attempted to be installed). The destdir is optional; if you don't list it, the source code is downloaded (temporarily) into the /tmp directory. If you set it, make sure it isn't the same place as Your_Local_Library. If set, the source code (in a tar and compressed format) will be downloaded to the Where_To_Store_The_Download directory; then, you have a permanent copy of the source code for the package (if you ever need to reinstall it).
Miscellaneous
When running R, if you type this command
library()
A list of all libraries in the Root R library directory and your Local Library will be listed.
