Installing a R package on the clusters

To install a R package, you need to use the install.packages() command. By default, it will try to save the installed package in the global library where a regular (non-root) user cannot write.

Using a local library

As R notes that it cannot write, it will ask whether you want to create a local library. Simply answer ‘y’ to that question to get started.

ceciuser@cecicluster:~ $ R

R version 2.13.1 (2011-07-08)
Copyright (C) 2011 The R Foundation for Statistical Computing
ISBN 3-900051-07-0
Platform: x86_64-redhat-linux-gnu (64-bit)
[...]

The .libPaths() command lists the places where R will search for libraries, and use the first item of the list as target for new package installs.

> .libPaths()
[1] "/usr/lib64/R/library" "/usr/share/R/library"

Let’s install the dummy package

> install.packages('dummy')

R tries to install it in the global library

Installing package(s) into ‘/usr/lib64/R/library’
(as ‘lib’ is unspecified)
Warning in install.packages("dummy") :
  'lib = "/usr/lib64/R/library"' is not writable

but quickly notes that it cannot write in the global place, and asks whether it should create a local library. Simply answer ‘y’.

Would you like to create a personal library
'~/R/x86_64-redhat-linux-gnu-library/2.13'
to install packages into?  (y/n) y

and the installation process resumes as usual.

--- Please select a CRAN mirror for use in this session ---
Loading Tcl/Tk interface ... done
trying URL 'https://www.freestatistics.org/cran/src/contrib/dummy_0.1.3.tar.gz'
Content type 'application/x-gzip' length 3710 bytes
opened URL
==================================================
downloaded 3710 bytes

* installing *source* package ‘dummy’ ...
** R
** inst
** preparing package for lazy loading
** help
*** installing help indices
  converting help for package ‘dummy’
    finding HTML links ... done
    categories                              html
    dummy                                   html
    dummyNews                               html
** building package indices ...
** testing if installed package can be loaded

* DONE (dummy)

The downloaded packages are in
  ‘/mnt/fhgfs/RtmpgDN1Y8/downloaded_packages’
> q()
Save workspace image? [y/n/c]: n

After that, the new package is installed in the user’s home directory:

ceciuser@cecicluster:~ $ ls R/x86_64-redhat-linux-gnu-library/2.13/dummy/
DESCRIPTION  help  html  INDEX  Meta  NAMESPACE  NEWS  R

Note that R saves the configuration for future uses:

ceciuser@cecicluster:~ $ R

[...]

> .libPaths()
[1] "/home/users/d/f/ceciuser/R/x86_64-redhat-linux-gnu-library/2.13"
[2] "/usr/lib64/R/library"
[3] "/usr/share/R/library"

The libPaths() command now lists the home directory as the first item. Therefore, subsequently installed packages will be saved in the home directory.

> library(dummy)
dummy 0.1.3
dummyNews()
> install.packages('test')
Installing package(s) into ‘/home/users/d/f/ceciuser/R/x86_64-redhat-linux-gnu-library/2.13’
(as ‘lib’ is unspecified)
--- Please select a CRAN mirror for use in this session ---
Loading Tcl/Tk interface ... done
[...]

Final remarks

Computer-nodes can have different architectures , if you install the package in the font-end of a cluster with multiple architectures, you need to use --constraint option in your submission script to use only the set of computes nodes with the same architecture than the front-end.

You can see the front-end architecture with the command:

lscpu | grep "Model name"

To see the compute nodes architecture use the command:

info -o "%20N %20P %b"

If the package you want to install has operating system-level dependencies (i.e. the package depends on core libraries), then you will need to ask the system administrator to install the package.

If you feel that the package you want to install is useful for many users, you can also ask a system administrator to install it globally.

Finally, note that packages depend on the R version you are using. Make sure to load the right module before you install a package!