Skip to end of metadata
Go to start of metadata

You are viewing an old version of this content. View the current version.

Compare with Current View Version History

« Previous Version 4 Next »

Installing R packages on the HPC (Not Needed Today)

When you come to running your own R scripts on the HPC, you will need to install the packages your script needs. We have done this for you for this training session but to install your own packages you can follow a procedure like this:

bioconductor_packages <- c("clusterProfiler", "pathview", "AnnotationHub", "org.Hs.eg.db")
cran_packages <- c("tidyverse", "ggplot2", "plyr", "readxl", "scales")
# Compares installed packages to above packages and returns a vector of missing packages
new_packages <- bioconductor_packages[!(bioconductor_packages %in% installed.packages()[,"Package"])]
new_cran_packages <- cran_packages[!(cran_packages %in% installed.packages()[,"Package"])]
# Install missing bioconductor packages
if (!requireNamespace("BiocManager", quietly = TRUE))
  install.packages("BiocManager")
BiocManager::install(new_packages)
# Install missing cran packages
if (length(new_cran_packages)) install.packages(new_cran_packages, repos = "http://cran.us.r-project.org")
# Update all installed packages to the latest version
update.packages(bioconductor_packages, ask = FALSE)
update.packages(cran_packages, ask = FALSE, repos = "http://cran.us.r-project.org")

Save this as install.R

You can then run this on the HPC like before with this submission script:

#!/bin/bash -l
#PBS -N R_install
#PBS -l select=1:ncpus=1:mem=4gb
#PBS -l walltime=2:00:00
#PBS -m abe
module load r/4.2.1-foss-2022a
cd $PBS_O_WORKDIR
mkdir -p r_library
export R_LIBS_USER='$PBS_O_WORKDIR/r_library'
Rscript install.R

Save this as install.pbs

Run this on the HPC:

# Submit the job to the HPC
qsub install.pbs
# Check the status of the job
qjobs
  • No labels