A R kernel in IPython notebook: Jupyter

jupiterR

After having become familiar with Ipython and its notebook mode (thanks to the MOOC Python pour les Scientifiques) , which allows to use the python language in an interactive and online way through a web browser, the familiarization with the R language through a more traditional (even if advanced) IDE like RStudio looks honestly like several steps backwards for the purpose of learning or teaching or taking notes (using Markdown). In fact, even for a Data Science study, or initial analysis, this working method has several distinct advantages, allowing to perform calculations and documenting the code and the results with the possibility of including high rendering quality Latex formulas in the Markdown (or plot labels).

I was just thinking that it would be nice if the same type of environment would be available also for R. But of course when things are so evident, there must be also somebody else that thinks in the same direction. The internet gives us this warm feeling of not being alone.

In this case, these are the people behind the development of IPython.

By installing a new version of IPython, It is now possible to install different types kernels to be used from inside IPython notebooks. One of these kernels is IRKernel, which is basically R.

To do this, you will need to update IPython notebook to the latest version, this can be done like this:

I am using Ubuntu, it was complaining that I did not uninstall the previous version and that I missed some modules. I checked the error messages and then installed all of them using:

my first advice is to install the latest version of R or you will have dependencies and package download problems in R. This is especially true when using the Ubuntu Trusty 3.02 standard build of R. You do this by following the instructions provided here.

After the upgrade, then follow the instructions provided here, and here and that are clear enough so I do not repeat them. I have stopped at R because this is what I am learning now, but you can install kernels for other languages as well. Let us concentrate on R.

Following  the instructions, if everything runs smoothly, you will end up running from the R shell the last command, which starts a R Kernel:

What you will see is that the title of your IPython notebook in your web browser will change from IPython to Jupiter. This can be seen by pointing your browser to http://localhost:8888/tree.

On the right side, in the kernels drop down list shall now display the running R Kernel. In fact, even when you run:

From the command line, the option is available. You do not need to go into the R shell at all.

jupiter1If you now select R, a new notebook shall open in which you can start typing your R experiments, just as you used to do in Python (I tried to keep the image compact) :

jupiter2

Well, that’s it, from now on you can play with R in the same nice environment as you used to do with Python! Enjoy (More tricks coming up later)!

Leave a Reply