R package installations

The system installed R only contains default packages. Other packages need to be installed by the user explicitly. User installed R packages are located in the user’s /home directory. 

There are two common ways for R package installation. 1) Installing packages interactively and 2) Installing packages using R CMD INSTALL

Installing packages interactively

  1. Load the R module by command ‘module load R/4.0.2
  2. Start the R console by typing command ‘R
  3. Install a package using R command ‘install.packages()

Below is a quick example:

[jzhan61@clogin01 ~]$ module load R/4.0.2
[jzhan61@clogin01 ~]$ R

R version 4.0.2 (2020-06-22) -- "Taking Off Again"
Copyright (C) 2020 The R Foundation for Statistical Computing
Platform: x86_64-pc-linux-gnu (64-bit)

R is free software and comes with ABSOLUTELY NO WARRANTY.
You are welcome to redistribute it under certain conditions.
Type 'license()' or 'licence()' for distribution details.

  Natural language support but running in an English locale

R is a collaborative project with many contributors.
Type 'contributors()' for more information and
'citation()' on how to cite R or R packages in publications.

Type 'demo()' for some demos, 'help()' for on-line help, or
'help.start()' for an HTML browser interface to help.
Type 'q()' to quit R.

> install.packages('bayestestR')
Installing package into ‘/home/jzhan61/R/x86_64-pc-linux-gnu-library/4.0’
(as ‘lib’ is unspecified)
--- Please select a CRAN mirror for use in this session ---
Secure CRAN mirrors

 1: 0-Cloud [https]
 2: Australia (Canberra) [https]
 3: Australia (Melbourne 1) [https]
 4: Australia (Melbourne 2) [https]
 5: Australia (Perth) [https]
 6: Austria [https]
 7: Belgium (Ghent) [https]
 8: Brazil (BA) [https]
 9: Brazil (PR) [https]
10: Brazil (RJ) [https]
11: Brazil (SP 1) [https]
12: Brazil (SP 2) [https]
13: Bulgaria [https]
14: China (Beijing 1) [https]
15: China (Beijing 2) [https]
16: China (Hong Kong) [https]
17: China (Guangzhou) [https]
18: China (Lanzhou) [https]
19: China (Nanjing) [https]
20: China (Shanghai 1) [https]
21: Colombia (Cali) [https]
22: Costa Rica [https]
23: Denmark [https]
24: East Asia [https]
25: Ecuador (Cuenca) [https]
26: Ecuador (Quito) [https]
27: France (Lyon 1) [https]
28: France (Lyon 2) [https]
29: France (Marseille) [https]
30: Germany (Erlangen) [https]
31: Germany (Münster) [https]
32: Germany (Regensburg) [https]
33: Greece [https]
34: Hungary [https]
35: Iceland [https]
36: India [https]
37: Indonesia (Jakarta) [https]
38: Italy (Padua) [https]
39: Japan (Tokyo) [https]
40: Korea (Gyeongsan-si) [https]
41: Korea (Ulsan) [https]
42: Malaysia [https]
43: Mexico (Mexico City) [https]
44: Morocco [https]
45: Netherlands [https]
46: Norway [https]
47: Philippines [https]
48: Russia (Moscow) [https]
49: South Africa (Johannesburg) [https]
50: Spain (A Coruña) [https]
51: Sweden [https]
52: Switzerland [https]
53: Taiwan (Taipei) [https]
54: Turkey (Mersin) [https]
55: UK (Bristol) [https]
56: UK (London 1) [https]
57: USA (IA) [https]
58: USA (KS) [https]
59: USA (MI) [https]
60: USA (OH) [https]
61: USA (OR) [https]
62: USA (TN) [https]
63: USA (TX 1) [https]
64: Uruguay [https]
65: (other mirrors)

Selection: 63
trying URL 'https://cran.revolutionanalytics.com/src/contrib/bayestestR_0.7.2.tar.gz'
Content type 'application/octet-stream' length 2401975 bytes (2.3 MB)
==================================================
downloaded 2.3 MB

* installing *source* package ‘bayestestR’ ...
** package ‘bayestestR’ successfully unpacked and MD5 sums checked
** using staged installation
** R
** inst
** byte-compile and prepare package for lazy loading
** help
*** installing help indices
*** copying figures
** 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 (bayestestR)

The downloaded source packages are in
        ‘/tmp/RtmpiZOSFP/downloaded_packages’

Multiple packages can be installed using a single command:

install.packages(c('lme4','LaplacesDemon','quantreg','plyr','boot','broom','MASS','dplyr'))

Some R packages, require external compilers or additional libraries. If you see an error when installing your package you might need to load additional modules to make these compilers or libraries available. For more information about this, refer to the package documentation.

Installing packages using R CMD INSTALL

To install packages using R CMD INSTALL the zipped package must already be downloaded to the cluster. You can download the package source using wget. Then the R CMD INSTALL command can be used when pointed to the full path of the source tar file. For example, to install ggplot2 the following commands are used:

# Download the package source:
[jzhan61@clogin01 ~]$ wget https://cran.r-project.org/src/contrib/ggplot2_3.2.1.tar.gz

# Install the package:
[jzhan61@clogin01 ~]$ module load R/4.0.2
[jzhan61@clogin01 ~]$ R CMD INSTALL ./ggplot2_3.2.1.tar.gz