Code

Code

Friday, January 22, 2016

Using R in a Jupyter/Ipython Notebook with Ubuntu

I may have mentioned it before, but I love the Jupyter Notebook. It's the only way I come close to keeping my code and analyses organized. I'm not a huge fan of R, mostly because I'm not great at it, but I have to use it sometimes. Today was my third attempt at integrating the R kernel into the Notebook, and it took several hours. I figured it would be worthwhile to chronicle what finally worked, in case I need it later.

Here's my setup:

Ubuntu 14.04 LTS
CPython 2.7.11
IPython 4.0.1
R version 3.2.3 (2015-12-10)

I have no idea how well these steps would work with any variation in any of these versions. One thing I do know, using R 3.2.x is critical. I was previously using R 3.0.2, which turned out to be the difficulty. 3.0.2 continues to be the default download of R on Ubuntu, so a couple of extra steps are necessary to get 3.2.3 So, if you need to upgrade R:
  1. Open the 'Ubuntu Software Center'.
  2. Edit -> Software Sources.
  3. Click the 'Other Software' tab.
  4. Click the 'Add' button.
  5. Fill in 'deb http://cran.fhcrc.org/bin/linux/ubuntu trusty/'
  6. Click the '+ Add Source' button. 
This will allow apt-get to properly upgrade R. You can then go to your terminal:

$sudo apt-get update
$sudo apt-get upgrade
$sudo apt-get install r-base r-base-dev

At this point you should have a proper version of R. Next we can start working on kernel dependencies. Also from the terminal, run:

$sudo apt-get install libzmq3-dev

We're almost done. From inside R (using either the terminal or an IDE like RStudio), run:


install.packages(c('rzmq','repr','IRkernel','IRdisplay'),
                 repos = c('http://irkernel.github.io/', getOption('repos')),
                 type = 'source')
IRkernel::installspec()

And there you go! Things should be up and running now, and you should have the option to create an R notebook:

No comments:

Post a Comment