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 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 r-nlme

# Install lme4 (linear mixed models)
conda install -c 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

9 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.


    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 🙂


  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 !!”


    1. Hi there, thanks for the comments! This post is actually quite old now (before Anaconda properly supported R) and therefore I’m not surprised that some of it isn’t quite working anymore.

      Since R is now fully supported in conda I would recommend installing MRAN (Microsoft R) through conda since it uses multithreaded linear algebra routines. Any libraries can then be installed within R using the install.packages command.


      1. Thank you for replying. I am trying to use R in anaconda. ipython notebook can open using anaconda prompt but do i use command or syntax like library(dplyr),etc…. Thank you

      2. Once you’ve opened an R shell (in Jupyter notebook or R studio for example) you just need to type install.packages(“ggplot2”) etc.


Leave a Reply

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

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

Facebook photo

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

Connecting to %s