Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.

...

Installing R packages on the HPC (

...

when you come to do your own DE and FA analysis)

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:

First, in RStudio create a new R script (File → New File → R script), and save as install.R

Code Block
# This line will use the Canberra mirror for CRAN
chooseCRANmirror(graphics = getOption("menu.graphics"), ind = 3, local.only = TRUE)

# Sometimes you need to install packages from github, like this:
install.packages("devtools")
devtools::install_github("YuLab-SMU/ggtree")

# Sometimes you will have bioconductor packages
bioconductor_packages <- c("clusterProfiler", "pathview", "AnnotationHub", "org.Hs.eg.db")

# Sometimes you will have CRAN packages
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
# You may need to change the version of BiocManager depending on the bioconductor packages you need to install
if (!requireNamespace("BiocManager", quietly = TRUE))
  install.packages("BiocManager", version = "3.16")
BiocManager::install(new_packages, dependencies = TRUE, INSTALL_opts = '--no-lock')

# Install missing cran packages
if (length(new_cran_packages)) install.packages(new_cran_packages, repos = "httphttps://cran.us.r-project.orgcsiro.au/")

# Update all installed packages to the latest version
update.packages(bioconductor_packages, ask = FALSE)
update.packages(cran_packages, ask = FALSE, repos = "httphttps://cran.us.r-project.orgcsiro.au/")

...



Then, in RStudio create a new Text File (File → New File → Text File), and save as install.R

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

pbs

Code Block
#!/bin/bash -l
#PBS -N R_install
#PBS -l select=1:ncpus=1:mem=4gb
#PBS -l walltime=2:00:00
#PBS -m abe

cd $PBS_O_WORKDIR

module purge
module load r/4.2.12-foss-2022a
cd2022b
mkdir -p $PBS_O_WORKDIR
mkdir -p /r_library
export R_LIBS_USER='$PBS"${PBS_O_WORKDIR}/r_library'"
echo $R_LIBS_USER

Rscript install.R

Save this as install.pbs

Run this on the HPC:

Code Block
# Convert the launch_R.pbs to Linux format
dos2unix install.pbs
# Submit the job to the HPC
qsub install.pbs
# Check the status of the job
qjobs