How to Install R kernel for IPython Jupyter on Mac OSX Yosemite

IPython is a great tool for developers, particularly for R programmers who are accustomed to the luxury of running blocks of code during development. The ability to add an R kernel to the IPython environment gives one the ability to run Python and R side-by-side in the same programming environment.

But there’s a catch… A base requirement is the rzmq package for R. The package isn’t on CRAN and doesn’t load correctly using Devtools, leaving many people out in the cold.

Update: This install method is shorter and works the same.

Get zmq dependencies. Note: Make sure you’ve got Xcode installed.

For Homebrew:

xcode-select --install 
brew install zmq

or if you prefer MacPorts:

sudo port install zmq
export CPATH=/opt/local/include 
export LIBRARY_PATH=/opt/local/lib

Next, fire up R, install from source and start your kernel.

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

That should work. If not, the instructions below show you how to clone the IRkernel GitHub repo and install from source on your local machine.

My original install method.

Installing R Kernel for IPython

This tutorial is for Mac OS X Yosemite. If you’re running Linux there is a similar tutorial here.

A few things you should have first.

  • IPython installed
  • R installed with RCurl and Devtools
  • Python installed
  • Homebrew installed

Open the terminal and brew up a couple dependencies:

brew install libzmq3

brew install czmq zmq

Assuming that those libraries brewed without any errors, start R in your terminal by typing “R” or fire up R-Studio. Install these three packages. Note, it may be a good idea to install them one at a time. Note, since the rzmq package includes dependencies, we’ll be cloning the GitHub repo and installing it locally.

In the terminal:

git clone https://github.com/armstrtw/rzmq.git --recursive

Make sure to place the file in your R working directory. Then in R:

library(RCurl)
library(devtools)

install_local('./rzmq')  

install_github('IRkernel/repr')

install_github("IRkernel/IRdisplay")

install_github("IRkernel/IRkernel")

At this point the R kernel should work (in theory) by executing the installspec() function from your new IRkernel package but…

In my case, installspec() wouldn’t fire up, so I did a little detective work. Run the following command in R to find the path IRkernel is hitting.

print(system.file("kernelspec", package = "IRkernel"))

Chances are the package is sending the R kernel to somewhere like “/Library/Frameworks/R.framework/Versions/3.1/Resources/library/IRkernel/kernelspec”.

If that is the case, then you’ve quickly found the problem that took me hours of detective work to track down.

In that case, there is a simple work-around. In your terminal type:

ipython kernelspec install --replace --name ir --user /Library/Frameworks/R.framework/Versions/3.1/Resources/library/IRkernel/kernelspec

After you run that in terminal, go back into R and run:

library(IRdisplay)
library(IRkernel) 

installspec()

At this point you should be set to go. Fire up your terminal one more time, throw the IPython command and keep your fingers crossed!

ipython notebook

My environment = OS X 10.10, R 3.1, Python 3, your results may vary!

If you get stuck, I probably can’t help but there is another resource here. This method didn’t work for me but you may have better luck!

10 thoughts on “How to Install R kernel for IPython Jupyter on Mac OSX Yosemite

  1. brew install libzmq3
    Error: No available formula for libzmq3
    Searching formulae…
    Searching taps…

    libzmq3 not found. What to do and also install_github(‘armstrtw/rzmq’) did not work. make: *** [rzmq.so] Error 127
    ERROR: compilation failed for package ‘rzmq’

    1. Both errors look like they have to do with zmq. Are you able to run “brew install zmq”? Also, make sure you’ve got XCode and/or Command Line Tools installed.

  2. I’m running Mac OS X Yosemite and likewise I am unable to follow your recipe. I get the same problem as Subinoy: When I tried “brew install libzmq3” I got Error: no available formula for libzmq3. To answer your questions: when I do “brew install zmq” I get “Warning: zeromq-4.1.3 already installed”, and yes, I have XCode as well as command line tools installed. When I do “xcode-select –install” I am told they are already installed.

  3. Hey guys. I’m facing the same problem as Subinoy and gregp. That is, I get the error when trying to brew libzmq3. I have looked at other solutions but they didn’t work either. Has anyone been able to solve this problem?

Leave a Reply