Home » Running an R kernel in Google Colab

Running an R kernel in Google Colab

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.

https://colab.research.google.com/notebook#create=true&language=r

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.

Install packages

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.

Documentation

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.

Reading data

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.

Say thanks, ask questions or give feedback

Technologies get updated, syntax changes and honestly… I make mistakes too. If something is incorrect, incomplete or doesn’t work, let me know in the comments below and help thousands of visitors.

1 thought on “Running an R kernel in Google Colab”

  1. How do you mount Drive while you are still running R? I notice that you have provided a separate like with steps that show how to link Drive using Python.

Leave a Reply

Your email address will not be published. Required fields are marked *