R Jupyter Notebook + RStan on Google Colab

Hi every one,

I’ve created a simple notebook to support R and Rstan on Google Colab.

You just need to copy this notebook to your Google Drive.


I was inspired by

which supports Julia on Google Colab.

Having fun!


It should work from github too?

Yes It works on Github repo and Gist too.

Cool! Thanks for sharing. There’s also the version on RStudio that pulls up an RStudio session on the web rather than Jupyter. @andrewgelman has been looking for these to show new users without having to install Stan.

I couln’t use library() function. I can install packages but I can’t use them. Do you know how to solve this?
I believe using :: notation works. But I am trying to write something like, as(myMatrix, “realRatingMatrix”) and it can’t do this. recommenderlab::as() also not working.

Can you run the R code examples in my notebook successfully?


I used library() function in these examples and it seems to work correctly.

Hello Ari, I was unable to run the script on my Drive (sorry, newcomer on Colab).
The error:

–2019-03-03 19:31:33-- https://repo.continuum.io/miniconda/Miniconda3-latest-Linux-x86_64.sh
Resolving repo.continuum.io (repo.continuum.io)…,, 2606:4700::6812:c84f, …
Connecting to repo.continuum.io (repo.continuum.io)||:443… connected.
HTTP request sent, awaiting response… 200 OK
Length: 69826864 (67M) [application/x-sh]
Saving to: ‘Miniconda3-latest-Linux-x86_64.sh.4’
Miniconda3-latest-L 100%[===================>] 66.59M 130MB/s in 0.5s
2019-03-03 19:31:33 (130 MB/s) - ‘Miniconda3-latest-Linux-x86_64.sh.4’ saved [69826864/69826864]
mkdir: cannot create directory ‘/root/.R/’: File exists

Have any ideias on how to surpass it?
Thanks for all the work done here!


You may first have to reset your runtime by going to menu Runtime -> Reset all runtimes. After that, run Setup code. After 3 mins your runtime will be restarted. Now, go to Runtime -> Manage Session, and terminate your Session. Reconnect and skip the Setup code, run the R code.

1 Like


How could I install new packages like ggmap?




Recently, Google Colab had secretly supported R notebooks. We don’t need to install R and R jupyter kernel ourself anymore. All we need is selecting “ir” jupyter kernel. This hints that Google has the intention to fully support R in Colab in a near future.

Here is an example of a R notebook with rstan and ggmap installed: