To install an R package you will need to first manually download it from its website. Most popular packages are part of the CRAN archive. You will need to find a link to the source code of the package you require and download this with the wget or curl command. For example the LearnBayes package (https://cran.r-project.org/web/packages/LearnBayes/index.html) can be downloaded from https://cran.r-project.org/src/contrib/LearnBayes_2.15.1.tar.gz.
The package can now be installed by loading the R module and running R CMD INSTALL, then specifying the -l flag for a local install, the directory we wish to install in and finally the name of the package file we just downloaded.
module load R R CMD INSTALL -l ~/R/libs LearnBayes_2.15.1.tar.gz
Finally we need to tell R where to find the libraries we’ve installed. This is done by setting the R_LIBS environment variable with the export command. You might want to add this command to any Slurm scripts which you write for using with R.