r_packages.md 2.29 KB
Newer Older
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
+++
title = "Using R Libraries"
description =  "How to install R packages on HCC resources."
+++

Many commonly used R packages are included in the base R installation available on HCC clusters,
 such as `tidyverse` and `stringr`. However, users are able to install other packages in their 
user libraries.

- [Adding packages](#adding-packages)
  - [Installing packages interactively](#installing-packages-interactively)
  - [Installing packages using R CMD INSTALL](#installing-packages-using-r-cmd-install)

  
### Adding packages

There are two options to install packages. The first is to run R on the
login node and run R interactively to install packages. The second is to
use the `R CMD INSTALL` command.

#### Installing packages interactively

1.  Load the R module with the command `module load R`
    -  Note that each version of R uses its own user libraries. To
       install packages under a specific version of R, specify which
       version by using the module load command followed by the version
       number. For example, to load R version 3.5, you would use the
       command `module load R/3.5`
2.  Run R interactively using the command `R`
3.  From within R, use the `install.packages()` command to install
    desired packages. For example, to install the package `ggplot2`
    use the command `install.packages("ggplot2")`

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 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:

{{< highlight bash >}}
# Download the package source:
wget https://cran.r-project.org/src/contrib/ggplot2_3.2.1.tar.gz

# Install the package:
R CMD INSTALL ./ggplot2_2.2.1.tar.gz
{{< /highlight >}}

Additional information on using the `R CMD INSTALL` command can be
found in the R documentation which can be seen by typing `?INSTALL`
within the R console.