Installing an R Kernel in Jupyter

Jupyter is commonly thought of as a resource for python. But it works just as well with R. In this brief post I will show you how to create a Jupyter kernel for R, so you can run R line by line.

If you don't already have R follow these two instructions to download R and R studio. R studio isn't necessarily needed if you will be working in jupyter, but it's always a good piece of software to have.

INSTALLING R:

INSTALLING R STUDIO:

  • Go to http://www.rstudio.com, click on “Download RStudio” and follow the directions for your operating system.

R

Installing an R Kernel is actually extremely easy

The first thing you will want to do is open up an R console. You can do this in Rstudio if you already use that.

Then you will run the following two commands. Either by running a script or by entering them into the console:

  • install.packages('IRkernel')
  • IRkernel::installspec()

R_kernel_install

Open Jupyter Notebook

After running this in your our console you will then go to your terminal/anaconda prompt and type the following to launch Jupyter Notebook:

launch_jupyter

Which will launch your web browser with Jupyter. And like I mentioned earlier on the far right you can view your current kernels. As mentioned earlier, I have a few, one of which is R.

kernels

Now I can start programming in R

In [13]:
X_vals <- c(1,2,3,4,5)
y_vals <- c(1,2,4,8,16)
In [16]:
plot(X_vals,y_vals,
    col='blue', pch=12,
    main='R plot in Jupyter')