Installing an R kernel to use in Canopy's Jupyter Notebook

With Jupyter notebooks now being opened in a browser window (as of Canopy 1.6.1), you are now able to edit and run notebooks in Julia, Python, or R kernels. Below are the steps needed to install an R kernel to be used in Canopy's Jupyter installation.

For all platforms, R must be installed. Mirrors to R installers can be found here: 

https://cran.r-project.org/mirrors.html 

Instructions for installing can be found here:

http://irkernel.github.io/installation/

After installation you will be able to create a new notebook from within the Jupyter browser window in the R kernel. You will also be chance between a Python and R kernels using the Kernel --> Change Kernel menu.

Platform specific caveats:

Mac (tested on OSX 10.11):

All of the commands below are executed from a Canopy Terminal (accessible from the Tools menu in Canopy). 

From a Canopy terminal, install zmq using the instructions from the "Source" tab in the above installation instructions.

Homebrew can be installed by running:

ruby -e "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/master/install)"

To use Homebrew on OSX 10.11, you must first change the permissions on /usr/local by running:

sudo chown -R $(whoami):admin /usr/local

Macports can be installed by downloading installers from:
https://www.macports.org/install.php

After installing ZMQ, open an R Console in the Canopy Terminal by running: R 

In the R Console, run the following (as a single, long command): 

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

If this command fails to install (which it likely will), certain directories and symbolic file links will need to be created.

Take this error message for example:

Warning message:
In doTryCatch(return(expr), name, parentenv, handler):
unable to load shared object '/Library/Frameworks/R.framework/Resources/modules/R_X11.so':dlopen(/Library/Frameworks/R.framework/Resources/modules/R_X11.so, 6): Library not loaded: /opt/X11/lib/libICE.6.dylib 
Referenced from: /Library/Frameworks/R.framework/Resources/modules/R_X11.so
Reason: image not found

This indicates that R is looking for the file "libICE.6.dylib" in the directory "/opt/X11/lib/"

Quit the R Console by running: q()

It is likely that such a file exists on your computer, but in another location. In this instance, you can find the location of "libICE.6.dylib" by running:

sudo find / -name libICE.6.dylib

On my system, libICE.6.dylib was found in "/usr/X11/lib". Once this file is found, you can create a symbolic link to this file in the location that R is searching for it. For libICE.6.dylib, this can be accomplished by running:

sudo mkdir -p /opt/X11/lib/
sudo ln -s /usr/X11/lib/libICE.6.dylib /opt/X11/lib/libICE.6.dylib

After creating this link, run the "install.packages..." command in R again. If the install fails again with a similar error, repeat the above procedure to create a symbolic link to the file indicated by the new error message.

After the installation succeeds, run the following in the R Console to install the IRkernel to Jupyter:

IRkernel::installspec()

Installation should now be complete and the R kernel available in Jupyter notebooks.

 

Have more questions? Submit a request

Comments

Powered by Zendesk