How to run R on Jupyter ipython Notebooks?

r
ipython

#1

Hello R Users

Recently, I came across ipython notebooks by Jupyter. Is there any use we run / install R on these notebooks? Considering, these are massive number of R users across the world, I presume there must be some hack / technique to install R on these notebooks.

I am keen to find this out. Please help!

Regards
Indu


#2

Hello Indu

Have you installed any ipython notebook in your machine yet?
Anyways, I’m going to elaborate the steps that helped me to run R on Jupyter ipython notebooks from scratch.

To enable R in Jupyter, you will need IRKernel (dedicated kernel for R) which is available at github. Below are the complete steps which I followed:

Step1: Download Anaconda from here: Anaconda Download In simple words, ipython notebooks live in Anaconda software. It is highly recommended for Jupyter notebooks

**Step 2:** After you've successfully downloaded, open 'Anaconda Command Prompt'. Faster way is to search it in your OS. Anaconda command prompt looks like this.
**Step 3:** Now type the following commands in prompt
ipython notebook

Voila! you’ve finally started your first ipython notebook. It looks like this:

Click on ‘New’ on the right. You will only find Python 2 in your notebooks section. Lets add R now.

Step 4: Update your ipython notebook with this command (screenshot below)

conda update ipython-notebook


Step 5: Install IRkernel (screenshot below)

conda install -c r ipython-notebook r-irkernel


Step 6: You can now open R in your commands prompt with this command.

R.exe


Step 7: Install some necessary packages used by R kernel on ipython notebook

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


Step 8: After the packages are successfully downloaded and installed. Type this:

IRkernel::installspec()


Step 9: Type quit

quit()

**Step 10:** Start your ipython notebook now
ipython notebook

Congratulations! You’ve now installed R in your ipython notebook.


**Click on R and start working.**

#3

@indutaneja11 Just to add to what Manish has already stated: if you’re primarily an R user and are planning to install Jupyter via Anaconda, I would recommend Miniconda instead (it’s from the same people). It’s about a tenth of the size and installs only the most basic packages, on top of which you can install whatever else you want (using the steps provided above).


#4

Excellent stuff Manish! Thanks for this. :slight_smile:


#5

Thanks @Aarshay :slight_smile:


#6

If you have Anaconda installed on your machine…then just type
conda install -c r r-essentials
on your terminal & it will install R kernal as well as some of the important R packages (like dplyr, ggplot2 etc).
For more details look at this link - https://www.continuum.io/blog/developer/jupyter-and-conda-r


#7

Does anybody know where the kernel.json for R is located? I can find the kernels of my base Anaconda and envs in “/user/.../jupyter/kernels/”, in the “python2” and “python3” subfolders, but no “r” subfolder is present here.
Thank you!


#8

This is the best way to do it.


#9

Another useful link which helped me is https://conda.io/docs/user-guide/tasks/use-r-with-conda.html .