Skip to content

Instantly share code, notes, and snippets.

@jsoma
Last active January 25, 2024 14:44
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save jsoma/52822565926eacfb786f8464a3b93b12 to your computer and use it in GitHub Desktop.
Save jsoma/52822565926eacfb786f8464a3b93b12 to your computer and use it in GitHub Desktop.
Installing R that works in Jupyter without the 1997 American adventure horror thriller film Anaconda

Installing R in Jupyter notebooks without Anaconda

You need to already have Jupyter installed! If you don't have Python+Jupyter set up, you could use Python Wrangler or you can honestly just go install Anaconda to get started more quickly.

Download R

You can find it at https://cloud.r-project.org. It’s hard to figure out where exactly to go, so here are direct links that might be out of date:

Install R

By running the file you just downloaded

Run R

  • OS X: Open up Terminal, type R, hit enter
  • Windows: Run R from the start menu

Install some more stuff

Paste in the code below, hitting enter after each line to run it. This code installs a kernel for R, the thing that allows us to plug R into Jupyter Notebooks.

install.packages(c('repr', 'IRdisplay', 'evaluate', 'crayon', 'pbdZMQ', 'devtools', 'uuid', 'digest'))
devtools::install_github('IRkernel/IRkernel')
IRkernel::installspec()

The first line installs packages, just like pip does for Python. But it’s a little more annoying: R will ask you which mirror you want to download from (a.k.a. which server). Why can it not just pick one for us? I don’t know. Just pick the first one.

It also will give you some warnings about submodules and stuff when running the last two lines. Don’t worry, it’s probably all fine!

Test your installation

  • Start a new Jupyter Notebook server by running jupyter notebook from the command line
  • Click New to make a new notebook and confirm that R is now also an option in the New menu.
  • No errors? You’re all set!
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment