5

I have jupyter notebook installed, I also have R installed. Both work fine independently.

When I run jupyter with jupyter notebook, then try to open an ipynb file, I see

enter image description here

The only option in the dropdown is Python 3 (R is not an option).

Question

How do you open a jupyter notebook with an R kernel (on mac)?

Note

  • I tried jupyter notebook --runtime-dir /usr/local/bin/R but that was just guessing
  • Looks like the R kernel could be installed via pip?
Waldir Leoncio
  • 10,853
  • 19
  • 77
  • 107
stevec
  • 41,291
  • 27
  • 223
  • 311

2 Answers2

9

Open any R session (e.g. in RStudio is fine, or open terminal/bash and type R to start an R session).

Install the kernel with:

install.packages("devtools")
devtools::install_github("IRkernel/IRkernel")
IRkernel::installspec()

Close and reopen the notebook and the R kernel will now be available.

stevec
  • 41,291
  • 27
  • 223
  • 311
  • I have a similar problem. What prompt are you typing the above statements at? – composerMike Oct 27 '19 at 05:05
  • It works for me from any R prompt, I had RStudio installed so I ran it from there, but another option is to open terminal, type `R` to start the R interpreter, and run it there – stevec Aug 10 '20 at 00:06
  • maybe also worth considering `IRkernel::installspec(user = FALSE) # install system-wide` – jjrr Jan 12 '22 at 17:11
  • 1
    credits to https://richpauloo.github.io/2018-05-16-Installing-the-R-kernel-in-Jupyter-Lab/ – jjrr Jan 12 '22 at 17:11
  • 1
    The additional advice at https://stackoverflow.com/a/42698032/6255436 were also useful – havlock Feb 12 '22 at 18:42
1

If the R kernel does not appear as an option within a Jupyter notebook even after installing R, and one is using Anaconda, bringing up the conda prompt from the Start menu (Windows 10), and running the following commands may do the trick:

conda config --add channels r
conda install --yes r-irkernel

Credit to this post.

Antoni Parellada
  • 4,253
  • 6
  • 49
  • 114