Self-installing R Packages for BlueBEAR¶
First search at BEAR Applications to see whether the package you need is already installed, being aware that it may exist as a dependency of another R package or as part of the Bioconductor package.
BlueBEAR (via batch or interactive job)¶
The self-installation of R packages essentially involves defining a single environment variable and ensuring that the path it points at exists:
export R_LIBS_USER=${HOME}/R/library/${EBVERSIONR}/${BB_APPS_BASE}
Environment Variable
This environment variable should be defined after you have loaded all the modules you wish to use, as it uses information provided by the loaded R module.
Then from within R, execute the install.packages
command. By default
it will attempt and fail to use the main library but will subsequently
drop back to the user directory defined above:
> install.packages("vioplot")
Installing package into ‘/rds/homes/a/a-user/R/library/4.2.0/EL8-has’
(as ‘lib’ is unspecified)
Note that if you’re performing a CRAN install in a batch script (i.e.
non-interactively) you will need to specify a repo so that R doesn’t
ask for you to select a CRAN Mirror, e.g:
install.packages("vioplot", repos='https://www.stats.bris.ac.uk/R/')
.
You will also need to ensure that the directory specified by
$R_LIBS_USER
exists prior to launching R by including the following
command: mkdir -p "${R_LIBS_USER}"
.
BEAR Portal (via RStudio)¶
The self-installation of R packages from inside RStudio involves defining
a location for the packages to be installed, adding this location to the
R .libPaths
, and ensuring that the path it points at exists:
libdir <- paste(Sys.getenv('HOME'), "R/library", getRversion(), Sys.getenv('BB_APPS_BASE'), sep = "/")
dir.create(libdir, recursive = TRUE)
.libPaths(c(libdir, .libPaths()))
install.packages("vioplot")
Then to use this package in future sessions:
libdir <- paste(Sys.getenv('HOME'), "R/library", getRversion(), Sys.getenv('BB_APPS_BASE'), sep = "/")
.libPaths(c(libdir, .libPaths()))
library(vioplot)
Bioconductor Packages¶
When installing packages from Bioconductor, all packages should be from the same Bioconductor release. If you are basing self-installs on a R-bundle-Bioconductor module then these extra package installs should be from the same Bioconductor version as is provided by the module.
Attempting to mix Bioconductor packages from different releases, or from the Bioconductor devel, often results in errors and failures. We do not support installing packages from the Bioconductor devel on BlueBEAR.