How can I install R packages in my home directory?

You may want to install R libraries that are not provided in MSI's R modules. You can install them to your home directory using the following procedure. Note that some packages need specific versions of system libraries such as gcc, gsl, fftw etc. These packages have to be loaded by using 'module load' command before using R, and may additionally need to be linked within R. You should be able to find these requirements in the package documentation if the packages are on CRAN - packages installed from source or via GitHub (e.g. using the package 'devtools') may have more sparse documentation.
 
If the following methods do not work for a package, please check the package documentation. Error messages during package installation (e.g. "cannot find ___") may also provide some information on system dependencies that should be loaded beforehand. For packages with an extremely long list of dependencies, you may want to consider installing them via conda/mamba as a stand-alone environment (many R packages are available via Anaconda.org). 
 
Please note that many advanced packages will take longer to install than the time you are limited to on a login node - you will want to request a compute node (interactive or non-interactive) for many package installations.
 
For standard modules available through CRAN:
 
1) Load the desired R module
module load R/4.1.0
R
 
2) Use R's built-in install command:
> install.packages('qtl')
 
3) Select a CRAN mirror from the options listed
It is usually best to select a server that is geographically close to you. Here we select a server in Michigan:
...
71: Turkey (Istanbul) [https]
72: Turkey (Mersin) [https]
73: UK (Bristol) [https]
74: UK (London 1) [https]
75: USA (IA) [https]
76: USA (KS) [https]
77: USA (MI) [https]
78: USA (OH) [https]
79: USA (OR) [https]
80: USA (TN) [https]
81: USA (TX 1) [https]
82: Uruguay [https]
83: (other mirrors)
> 77
 
The library will then install automatically to your home directory.
 
4) Confirm installations by loading the libraries
> library(qtl)
 
If you are installing Bioconductor packages, the procedure is slightly different:
 
1) Load the desired R module
module load R/4.1.0
R
 
2) Use the Bioconductor installer
> if (!require("BiocManager", quietly = TRUE))
>    install.packages("BiocManager")
> BiocManager::install()
Bioconductor version 3.14 (BiocManager 1.30.16), R 4.1.0 (2021-05-18)
Installation paths not writeable, unable to update packages
  path: /panfs/roc/msisoft/R/4.1.0/lib64/R/library
  packages:
    BH, brew, brio, cachem, class, cli, clipr, crayon, credentials, crosstalk,
    desc, devtools, diffobj, digest, DT, evaluate, fansi, foreign, fs, gert,
    glue, htmltools, htmlwidgets, IRdisplay, IRkernel, jsonlite, knitr, later,
    lattice, lifecycle, magrittr, MASS, Matrix, memoise, mgcv, mime, nlme,
    nnet, openssl, pbdZMQ, pillar, pkgbuild, pkgload, R6, rcmdcheck, Rcpp,
    remotes, repr, rex, rlang, roxygen2, rpart, sessioninfo, spatial, stringi,
    survival, testthat, tibble, usethis, uuid, waldo, withr, xfun, xml2, yaml
Old packages: 'units'
Update all/some/none? [a/s/n]:
> n
> BiocManager::install(c("GenomicRanges", "AnnotationDbi"))
...
** building package indices
** installing vignettes
** testing if installed package can be loaded from temporary location
** testing if installed package can be loaded from final location
** testing if installed package keeps a record of temporary installation path
* DONE (GenomicRanges)
>
 
3) Confirm installation by loading the libraries
> library('GenomicRanges')
Loading required package: stats4
Loading required package: BiocGenerics
 
Attaching package: ‘BiocGenerics’
 
The following objects are masked from ‘package:stats’:
 
    IQR, mad, sd, var, xtabs
 
The following objects are masked from ‘package:base’:
 
    anyDuplicated, append, as.data.frame, basename, cbind, colnames,
    dirname, do.call, duplicated, eval, evalq, Filter, Find, get, grep,
    grepl, intersect, is.unsorted, lapply, Map, mapply, match, mget,
    order, paste, pmax, pmax.int, pmin, pmin.int, Position, rank,
    rbind, Reduce, rownames, sapply, setdiff, sort, table, tapply,
    union, unique, unsplit, which.max, which.min
 
Loading required package: S4Vectors
 
Attaching package: ‘S4Vectors’
 
The following objects are masked from ‘package:base’:
 
    expand.grid, I, unname
 
Loading required package: IRanges
Loading required package: GenomeInfoDb
Category: 
Software