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:
First, in RStudio create a new R script (File → New File → R script), and save as install.R
# 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 have 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", 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 = "https://cran.csiro.au/") # Update all installed packages to the latest version update.packages(bioconductor_packages, ask = FALSE) update.packages(cran_packages, ask = FALSE, repos = "https://cran.csiro.au/")
Then, in RStudio create a new Text File (File → New File → Text File), and save as install.pbs
#!/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.2-foss-2022b mkdir -p $PBS_O_WORKDIR/r_library export R_LIBS_USER="${PBS_O_WORKDIR}/r_library" echo $R_LIBS_USER Rscript install.R
Run this on the HPC:
# 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