R Jupyter Notebook + RStan on Google Colab

Hi, please try a newer version. We don’t have to install R anymore because Google Colab has supported it already.

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

2 Likes

Hi,

How to load csv files through R in google colab?

I am very sorry, as this is EXACTLY what I am looking for, but regarding the comment:

We don’t have to install R anymore because Google Colab has supported it already.

When I create a new notebook on Google Collab, am I am able to just start coding in R? It fails for me currently and it is not abundantly clear to me why we don’t have to install R.

Simply, how can I explicitly show how this is done?

I am very encouraged by this.

I didn’t notice the small link, though this implies we install it on our own, so I suppose my question still stands.

hi, this is super awesome!

how can I access my Google drive from an R notebook?

I’m looking for the equivalent of the hacks discussed for Python notebooks in this SO question:

if this were possible, would it solve the problem of having to install packages at the beginning of each session?

same question here - I’ve uploaded a notebook and a Stan program file to the “colab” folder on my Google drive. all I want to do is:

cat(read_file("colab/simplest-regression.stan"))

but this fails with error:

Error: 'colab/simplest-regression.stan' does not exist in current working directory ('/content').

do I have to put all files on GitHub in order to access them?
this works:

cat(read_file("https://raw.githubusercontent.com/jgabry/bayes-workflow-book/master/stan/simplest-regression.stan"))

what worked for me was to first install the R jupyter notebook on my local machine, then create an R notebook locally, and then upload the notebook to my GitHub drive, at which point Colab recognized that it was an R notebook.

instructions here: https://irkernel.github.io/installation/

if you try to create a new notebook directly from Colab, the only runtime choices are Python2 or Python3.

Can you check your folder files with !ls in jupyter notebook?

Python runtime notebooks, yes -

!ls
sample_data
!pwd
/content

for R runtime notebooks in colab, you can do:

getwd(); list.files()
'/content'
'sample_data'

There’s now a case study for CmdStanR and CmdStanPy notebooks on Google Colab:

https://mc-stan.org/users/documentation/case-studies/jupyter_colab_notebooks_2020.html

1 Like

Newbie here :)
I keep getting the same error:
Error in library(“rstan”): there is no package called ‘rstan’
Traceback:

  1. library(“rstan”)

what notebook are you trying to run?

Hi,
thanks for the reply. I solved my issue using this notebook:

I was trying the notebook posted by @Thinking_Machine :