Using R

Install an R kernel for Jupyter

Some members of the community have asked to install R packages on SherlockML, to use an R kernel in a Jupyter notebook. To do this, create a new Conda environment with R and the main R data science libraries installed.

First deactivate the current Conda environment from a terminal with:

source deactivate

Next, create a new environment with R. The Anaconda team maintains an “R Essentials” bundle with the IRKernel and over 80 of the most common R packages for data science, including dplyr, shiny, ggplot2, tidyr, caret, and nnet.

To create a new environment and installing the r-essentials package:

conda create --name R --channel r r-essentials

When Conda finishes installing the packages, you can change to your new environment with:

source activate R

You can now run R from your Jupyter notebooks! Try opening a new notebook and running:

ggplot(data=iris, aes(x=Sepal.Length, y=Sepal.Width, color=Species)) + geom_point(size=3)

Installing new R packages

To install packages that are not part of “R Essentials”, first install the conda-build package with:

source deactivate

conda install conda-build

In the R environment, we can now use conda skeleton to build Conda packages for R packages that are already available on CRAN. Let’s install gam:

source activate R

conda skeleton cran gam

This generates meta.yml,, and files under a folder named r-gram. Note that even though the R package is called gam, the Conda package is called r-gam to avoid name conflicts with packages from other languages. We can then run:

conda build r-gam

which gets you the package /opt/anaconda/conda-bld/linux-64/r-gam-1.14-r3.3.2_0.tar.bz2

The package is now installed and available in your Jupyter notebooks.