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.

https://colab.research.google.com/drive/1xj_aYLBBPX2oSQ1I4xp5_YZiVhhpC1Ke

I was inspired by

which supports Julia on Google Colab.

Having fun!

5 Likes

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?

https://colab.research.google.com/drive/1xj_aYLBBPX2oSQ1I4xp5_YZiVhhpC1Ke

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)… 104.18.200.79, 104.18.201.79, 2606:4700::6812:c84f, …
Connecting to repo.continuum.io (repo.continuum.io)|104.18.200.79|: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!

Hi,

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

Hi,

How could I install new packages like ggmap?

Thanks,

Rob

Hi,

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:
https://colab.research.google.com/drive/1BYnnbqeyZAlYnxR9IHC8tpW07EpDeyKR

4 Likes

Hi,

I keep getting this error : mkdir: cannot create directory ‘/root/.R/’: File exists
when I run the first code segment
what does this mean?

Do you have a code that works for windows?

You should use the new notebook https://colab.research.google.com/drive/1BYnnbqeyZAlYnxR9IHC8tpW07EpDeyKR
which is supported by Google servers.

The notebook runs on Google colab servers (which is free). I’m pretty sure that it will not work on Windows without a proper setup.

2 Likes

I’m using the notebook you created for R. It’s amazing. Everything works until i tried to install the package “rgl”, or better “ConsRank” which needs “rgl”.
Could anyone help me somehow? Please, i’m working for my PhD results :(

This is what appears:

Warning message in install.packages(“rgl”, repos = “http://cran.rstudio.com/”):
“installation of package ‘rgl’ had non-zero exit status”Updating HTML index of packages in ‘.Library’
Making ‘packages.html’ … done
also installing the dependency ‘rgl’

Warning message in install.packages(“ConsRank”, repos = “http://cran.rstudio.com/”):
“installation of package ‘rgl’ had non-zero exit status”Warning message in install.packages(“ConsRank”, repos = “http://cran.rstudio.com/”):
“installation of package ‘ConsRank’ had non-zero exit status”Updating HTML index of packages in ‘.Library’
Making ‘packages.html’ … done

Hi,

The below 3 lines work for me (after 10 mins of running)

install.packages("rgl", repos = "http://cran.rstudio.com/")
install.packages("ConsRank", repos = "http://cran.rstudio.com/")
library("ConsRank")

My rule of thumb is that when something is wrong, reset your google colab instance.

1 Like

I run the commands at the beginning of the notebook. This could solve your problem.


I tried too but nothing changes. Is my problem in your opinion due to the fact i’m using a MAC Os? I guess there is a problem in managing the directory of the libraries, i have the same problem as you can see even in installing the library “ggmap”. I’m getting crazy

Your notebook is running on Google server so really nothing related to your computer.

Please clone this notebook as an example:

https://colab.research.google.com/drive/1ou6GKwmEq9Jj2xt2j-t8M_m8WGJWDv2i

Before running it, don’t forget to reset the server at the menu Runtime -> Reset all runtimes…

1 Like

Hi,
I am trying to run the set up code provided to run R on it. But my sessions are crashing again and again. I have reset the runtime session but still it is not running.