# R Packages

On Monsoon, you can install R packages to expand the functionality of your R projects.

## Installing R Packages

To install a package in R, open an R shell and use the `install.packages` function:

```bash
[abc123@wind ~] module load R
[abc123@wind ~] R
> install.packages(c("package1","package2",...,"packageN"))
```

In this form, R will prompt you for the repository mirror you want to use and will install each package in turn, including any dependencies. You will also be prompted for the location to store your installed package, which defaults to `/home/<username>/R/<R version>/packagename`.

## Specifying CRAN Mirror

To prevent R from prompting for the CRAN mirror to use, you can specify one within the `install.packages` function:

```R
> install.packages(c("package1"), repos = "http://cran.case.edu")
```

The same format works for other repositories such as Bioconductor, R-forge, etc.

## Installing From GitHub

To install packages from GitHub sites, we highly recommend referring to the GitHub project documentation. However, a general GitHub package installation can be done using the `require` and `install_github` functions:

```R
require(devtools)
install_github("package1")
```

## Advanced Configurations

For more complex installations that require other specific libraries, you can specify configure.vars to specify include and library paths. For example, to install the `rzmq` package, you'd need the `zeromq` module loaded before starting R and you'd need to specify the include and library paths:

```bash
[abc123@wind ~]$ module load zeromq R/3.6.0
[abc123@wind ~]$ R
> install.packages(c('rzmq'),repos = "http://cran.case.edu", configure.vars="INCLUDE_DIR=/packages/zeromq/3.2.5/include LIB_DIR=/packages/zeromq/3.2.5/lib")
```

Finally, you can use `pkg-config` for packages that want it, as well. This example installs the `rjags` package:

```bash
[abc123@wind ~]$ module load jags
[abc123@wind ~]$ export PKG_CONFIG_PATH=/packages/jags/4.3.0/lib/pkgconfig
[abc123@wind ~]$ pkg-config ––modversion jags
[abc123@wind ~]$ R
> install.packages(c('rjags'),repos = "http://cran.case.edu", configure.args="––enable-rpath")
```

As always, please don't hesitate to [contact us](<https://rcdata.nau.edu/hpcpub/docs-test/contact-us.html>) if you need further assistance with R package installation.
