Where are R Packages Installed on the Cluster?

Goal: Understand where R installs packages and where libraries are located, as well as inspecting general R system configuration.



Terminology Package vs Library

R-Bloggers: Packages v. Libraries in R: Packages are collections of R functions, data, and compiled code in a well-defined format. The directory where packages are stored is called the library:

  • A package is a directory of files which extend R, either a source package (the master files of a package), or a tarball containing the files of a source package, or an installed package, the result of running R CMD INSTALL on a source package. On some platforms there are also binary packages, a zip file or tarball containing the files of an installed package which can be unpacked rather than installing from sources.

  • A package is not a library. The latter is used in two senses in R documentation. The first is a directory into which packages are installed, e.g. /usr/lib/R/library: in that sense it is sometimes referred to as a library directory or library tree (since the library is a directory which contains packages as directories, which themselves contain directories). …


Load an R Environment via the Module System

[]$ module purge []$ module load gcc/13.2.0 r/4.4.0 []$ R --version R version 4.4.0 (2024-04-24) -- "Puppy Cup" ... # Run a simple function. []$ R -e "print(version[['version.string']])" R version 4.4.0 (2024-04-24) -- "Puppy Cup" ... > print(version[['version.string']]) [1] "R version 4.4.0 (2024-04-24)" # Run an R script. []$ Rscript r_test.R [1] "R version 4.4.0 (2024-04-24)"

Inspect R Environment Configuration

[]$ R R version 4.4.0 (2024-04-24) -- "Puppy Cup" ... # List ALL environment variables: > Sys.getenv() # Get single environment variable. > Sys.getenv("R_HOME") [1] "/apps/u/spack/gcc/13.2.0/r/4.4.0-pvzi4gp/rlib/R" # Get a list of environment variables. > Sys.getenv(c("R_PLATFORM", "R_HOME", "R_LIBS_USER")) R_PLATFORM "x86_64-pc-linux-gnu" R_HOME "/apps/u/spack/gcc/13.2.0/r/4.4.0-pvzi4gp/rlib/R" R_LIBS_USER "/cluster/medbow/home/<username>/R/x86_64-pc-linux-gnu-library/4.4"

Notice that User Libraries are stored under your home, in: R/x86_64-pc-linux-gnu-library/4.4

In general, under ~/R/<R_PLATFORM>/versionX.Y/


Get R Related Environment variables

Quick and dirty way to list all R_* environment variables.

[salexan5@mblog2 ~]$ R -e "Sys.getenv()" | grep R_ LMOD_FAMILY_COMPILER_VERSION ... R_HOME /apps/u/spack/gcc/13.2.0/r/4.4.0-pvzi4gp/rlib/R R_INCLUDE_DIR /apps/u/spack/gcc/13.2.0/r/4.4.0-pvzi4gp/rlib/R/include R_LIBS_SITE /apps/u/spack/gcc/13.2.0/r/4.4.0-pvzi4gp/rlib/R/site-library R_LIBS_USER /cluster/medbow/home/<username>/R/x86_64-pc-linux-gnu-library/4.4 ... R_PLATFORM x86_64-pc-linux-gnu ... R_SHARE_DIR /apps/u/spack/gcc/13.2.0/r/4.4.0-pvzi4gp/rlib/R/share ... R_UNZIPCMD /usr/bin/unzip R_ZIPCMD /usr/bin/zip thunderer_FAMILY_COMPILER_VERSION

Where are Packages Installed


How to Install Packages (from within R)


How to Install Packages (from outside of R)


Install tidyr Package


What’s Installed?


Remember: R Versions and Library Locations