Documentation/R packages hpc self library

From systems
Jump to: navigation, search

Setting the Local R Library Path and Package installation

To install packages to R on the HPC Cluster you will need to create your own library. Because default location will not be writable by your user account.

If you want to use another location rather than the default location, for example, /ifs/scratch/<your folder>/R_libs/ , you need to create the directory first:

mkdir /ifs/scratch/<your folder>/R_libs

Then type the following command inside R:

 install.packages("lattice", lib="/ifs/scratch/<your folder>/R_libs/")

If you want to install from specific repository you can specify it. for example if you want to use http://cran.r-project.org

install.packages("lattice", repos="https://cran.r-project.org", lib="/ifs/scratch/<your folder>/R_libs/")

It is a bit of burden having to type the long string of library path every time. To avoid doing that, you can create a file .Renviron in your home directory, and add the following line to the file:

export R_LIBS=/ifs/scratch/<your folder>/R_libs/ 

or

export R_LIBS_USER=/ifs/scratch/<your folder>/R_libs/ 

Whenever R is started, the directory /ifs/scratch/<your folder>/R_libs/ is added to the list of places to look for R packages and so:

 install.packages("lattice")

If you want to install from specific repository you can specify it. for example if you want to use http://cran.r-project.org

install.packages("lattice", repos="https://cran.r-project.org")

will have the same effect as the previous install.packages() command.

To see the directories where R searches for libraries, use the command:

.libPaths();


WARNING:

If you have library with a lot of packages in it already in your R_LIBS and/or R_LIBS_USER - when you try to install new packages after you select your mirror - it might look like it is stuck. R would look through all packages already available for dependency resolution. So for very large libraries that can take very long time.

Additional Suggestions

If you will be using different R version, then having separate libraries for them might be a good idea.
For example R_LIBS_311 and R_LIBS_353
Not all packages build for one version of R works with other and in some cases some older packages not available for new one etc.