In this blog post, I elaborate on running an R kernel within a Google Colab notebook and I demonstrate a range of basic functionalities.
In the FAQ of Google Colab, you can read that, for now, Google does not support kernels other than Python 3. Although they would like to, it’s not available yet.
“Colab focuses on supporting Python and its ecosystem of third-party tools. We’re aware that users are interested in support for other Jupyter kernels (eg R or Scala). We would like to support these, but don’t yet have any ETA.”
However, running R in Google Colab is possible! You can open the following link that creates a new notebook. By adding the language parameter, you can choose to create a notebook that will use the R kernel.
Most functionalities that you’re used to in RStudio should work. In the following paragraphs, I give a small overview of the basics.
Get to know the R version
To know which version is running in the notebook, you can simply request it using the R.version command.
To get an overview of the available packages, just use library(). You can install packages that don’t come out of the box. The install.packages function works as it should and they’re persistent. You don’t need to reinstall them when you restart the kernel. However, the packages will be removed when you do a factory reset of the runtime.
Finding documentation on the functions works as it should.
?sum # Works help(sum) # Works too
The documentation is opened on the right hand side of the interface (which you can change to horizontal layout). In my browser, I had some encoding errors, but it’s definitely complete.
Finally, by mounting your Google Drive, you can add and read data sets using read.csv() or fread().
To get the path to a file that’s stored on your Google Drive, you can copy the path from the file explorer within your notebook.