Installing R packages
On RCAC clusters, you can load any R modules (r-bioconductor
, r-rnaseq
, etc.) and install packages using BiocManager
or install.packages
. However, Since you don’t have write access to the system library, you will need to install the packages in your custom location. Here is how you can do it:
-
Create the required directory in your desired location. For home direcotry.
cd ~mkdir -p local/r_packagesThis is just an example, but you can project specific package directory if you prefer.
-
Install the packages in your custom library:
ml purgeml biocontainersml r-scrnaseq/4.4.1-rstudioRscript -e 'BiocManager::install("DESeq2", lib="~/local/r_packages")'Rscript -e 'install.packages("data.table", lib="~/local/r_packages")'You can also run this within an R session, if you prefer:
BiocManager::install("DESeq2", lib="~/local/r_packages")install.packages("data.table", lib="~/local/r_packages") -
Modify library path to ensure R knows about your custom library (modify
~/.Renviron file
file):echo 'R_LIBS_USER=${R_LIBS_USER}:'~/local/r_packages'' >> ~/.Renviron -
Test the installation:
ml purgeml biocontainersml r-scrnaseq/4.4.1-rstudioand in R session:
library(DESeq2)library(data.table).libPaths()This should load your libraries and should show the path to your custom library.
Using RStudio
Section titled “Using RStudio”Alternatively, if using RStudio, you can also set the environment variable in the RStudio configuration file. Add the following line to your ~/.Renviron file:
usethis::edit_r_environ()
When the file opens, add the following line:
R_LIBS_USER=~/local/r_packages
save and restart RStudio. You can test .libPaths()
in RStudio to see if the path is set correctly.