The directories in R where the packages are stored are called the libraries. The terms package and library are sometimes used synonymously and there has been discussion amongst the community to resolve this.
https://www.r-bloggers.com/2013/01/packages-v-libraries-in-r/
[salexan5@blog2 r]$ cat README.ARCC
We've created an R related workshop specific module file that loads the various additional modules (including openmpi/hdf5).
Use by calling from the command-line:Goal: Demonstrate how to use an R library to create a shared set of R packages. Code Block
...
Table of Contents | ||
---|---|---|
|
...
Use Case
Info |
---|
Consider the following use cases:
In both cases we can setup an R library within a shared location, such as a project folder, which all users can access, and thus use the same set of packages. |
...
General Process
Info |
---|
The general process for this is:
Every time this is to be used:
|
...
Example
Code Block |
---|
# Create R Library folder: []$ cd /project/arcc/software/ []$ mkdir -p r_library/r_workshop []$ cd r_library/r_workshop/ []$ pwd /project/<project-name>/software/r_library/r_workshop # Load and Start R []$ module |
...
purge []$ module load gcc/14.2.0 r/4.4.0 |
...
[]$ R # |
...
Check current library paths:
> .libPaths()
[1] "/cluster/medbow/home/<username>/R/x86_64-pc-linux-gnu-library/4.4"
[2] "/apps/u/spack/gcc/14.2.0/r/4.4.0-w7xoohc/rlib/R/library" |
...
Current Available R Packages
Code Block |
---|
> write.table(installed.packages()[,c(1,2,3:4)])
"Package" "LibPath" "Version" "Priority"
"class" "class" "/cluster/medbow/home/<username>/R/x86_64-pc-linux-gnu-library/4.4" "7.3-22" "recommended"
...
"XML" "XML" "/cluster/medbow/home/<username>/R/x86_64-pc-linux-gnu-library/4.4" "3.99-0.17" NA
"base" "base" "/apps/u/spack/gcc/14.2.0/r/4.4.0-w7xoohc/rlib/R/library" "4.4.0" "base"
...
"utils" "utils" "/apps/u/spack/gcc/14.2.0/r/4.4.0-w7xoohc/rlib/R/library" "4.4.0" "base" |
Info |
---|
Note: We can current see packages installed:
|
...
Update the Library Path
Info |
---|
Update the library paths to point to my newly created library folder, and the base packages. |
Code Block |
---|
> .libPaths(c('/project/ |
...
<project-name>/software/r |
...
_library/r_workshop', '/apps/u/spack/gcc/12.2.0/r/4.4.0-7i7afpk/rlib/R/library')) |
...
> write.table(installed.packages()[,c(1,2,3:4)]) "Package" "LibPath" "Version" "Priority" "base" "base" "/apps/u/spack/gcc/14.2.0/r/4.4.0-w7xoohc/rlib/R/library" "4.4.0" "base" ... "utils" "utils" "/apps/u/spack/gcc/14.2.0/r/4.4.0-w7xoohc/rlib/R/library" "4.4.0" "base" |
Info |
---|
Note: We can currently only see the base packages since we haven’t yet installed anything into |
...
Install a package into the New Library Location
Code Block |
---|
# Within R: > |
...
install.packages("Matrix") ... also installing the dependency ‘lattice’ ... * DONE (Matrix) > write.table(installed.packages()[,c(1,2,3:4)]) "Package" "LibPath" "Version" "Priority" "lattice" "lattice" "/cluster/medbow/project/<project-name>/software/r_library/r_workshop" "0.22-6" "recommended" "Matrix" "Matrix" "/cluster/medbow/project/<project-name>/software/r_library/r_workshop" "1.7-0" "recommended" "base" "base" "/apps/u/spack/gcc/ |
...
14.2.0/r/4.4.0- |
...
w7xoohc/rlib/R/library" "4.4.0" |
...
"base" ... "utils" "utils" "/apps/u/spack/gcc/ |
...
14.2.0/r/4.4.0- |
...
w7xoohc/rlib/R/library |
...
" "4.4.0" "base" # Lets check: []$ |
...
ls /project/<project-name>/software/r_library/r_workshop
lattice Matrix |
...
Test and Use
Error:
Code Block |
---|
[]$ cat r_library_test_fail.R
library(Matrix)
[]$ Rscript r_library_test_fail.R
Error in library(Matrix) : there is no package called ‘Matrix’
Execution halted
# The Matrix package is NOT available under our default library location. |
Success:
Note |
---|
Update the |
Code Block |
---|
[]$ cat r_library_test.R
.libPaths(c('/project/<project-name>/software/r_library/r_workshop', '/apps/u/spack/gcc/12.2.0/r/4.4.0-7i7afpk/rlib/R/library'))
library(Matrix)
[]$ Rscript r_library_test.R
[]$ |
...
Warning: Remember
Note |
---|
Within this example, by default this is a SHARED project location. Anyone who has access to this project and thus this shared library can update it. If an individual performs an |
Info |
---|
The project users will need to collaborate and come up with some form of data plan and/or process for the management of this shared library. |
...
Prev | Workshop Home | Next |