How to setup R using conda

Recently I’ve been working with some of the statistics staff at the University of Manchester on sports analytics. Specifically we’ve been looking for useful models in football data. People from this background normally use R to analyze data and fit models.

Normally I would use Python for this kind of task but, since there was already a considerable amount of code in R, it made sense for me to do some work in R. The people at Continuum Analytics (who make the brilliant Anaconda Python distribution) recently announced support for R using their package manager conda. However, it wasn’t easy to find instructions to get a fully working environment, so here is what I did.

Note: I am assuming that you are using Linux (probably works on Mac too) but I make no guarantees whatsoever that following this will get you a working environment!

You can enter the following into a Bash prompt.

# Create a new conda environment called r
conda create -n r anaconda

# Switch to r environment
source activate r

# Installs R
conda install -c r r

# Install R kernel for IPython notebook
conda install -c r r-irkernel

# Install ggplot
conda install -c https://conda.binstar.org/bokeh ggplot

# Install r-matrix, r-nlme, and some other useful libraries.
# This may raise an error but I haven't encountered any problems
conda install -c https://conda.binstar.org/asmeurer r-nlme

# Install lme4 (linear mixed models)
conda install -c https://conda.binstar.org/asmeurer r-lme4

You can now start up a Jupyter notebook, which is preinstalled with the R kernel, and start using R as follows.

ipython notebook
Advertisements

5 thoughts on “How to setup R using conda

  1. Hi Sam, very nice write-up on creating an R environment using conda. I’ve added a bunch of new info to our conda docs site recently, but none yet on setting up R environments. I’d love to link to your instructions or reproduce them for our users, with link and credit to you of course. Please let me know what is your pleasure.

    Kerry

    1. Hi Kerry,

      Thanks, I’m glad you think so! Please feel free to copy the instructions, you may as well reproduce them, and modify as you see fit, to avoid users needing to visit another page 🙂

      Sam

  2. Hi Sam,

    Thank you so much for this writeup. It works perfectly on Mac OSX El Capitan. So I guess you can remove the phrase “Probably works on mac too ” to “Works on mac as well !!”

    Thanks
    Babinu

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s