How to use R with Google Colab?
Last Updated :
13 Apr, 2025
Google Colab is a cloud based coding platform providing free access to limited resources like GPU or TPU. It comprises cells where one can write codes and execute them. It also provides the facility of sharing in real time. Some of the features are:
- It allows users to share notebooks in real time.
- It helps to import external datasets.
- It helps to upload notebooks.
- Most of the libraries are available in Google Colab. Hence very few libraries are required to be installed.
Ways to use R with Google Colaboratory
R is a programming language used for data analysis and statistical analysis. It provides a vast amount of libraries and tools that are required for data visualization. We can install the R programming language using the link 'How to install R'. However, Google Colab can also be used for R programming. There are two ways to use R with Google Colab.
1. Changing Runtime type
The first way is very simple. Below are the steps to follow:
1. Open the Google Colab and then click on the new notebook.
Opening Google Colab2. When the new Notebook opens click on the Runtime option that is available from the list of options.
Clicking on Runtime3. Then a dropdown appears. From the dropdown click on Change Runtime Type.
Click on Runtime type4. A dialog box appears. Under the heading Runtime type by default Python3 appears. Click on the arrow and change it to R. After that click on Save.
Choose R5. Execute any command of R. You will get to see the results.
Executing R commandsIn the above output we have created two vectors named vector 1 and vector 2 and created a plot for them.
2. Using rpy2
The second way is useful when you want to use both Python and R. The steps are as follows:
1. Open the Google Colaboratory and then click on the new notebook.

2. In the cell execute the command : %load_ext rpy2.ipython.
3. Now whenever you need to use R commands in each cell write %%R at the beginning followed by R commands.
4. After that execute the cell using Ctrl+Enter.
Executing R Using these two techniques one can use R on google colab without installing R package.
How to Save and open R file in Google Colab?
Google Colab automatically saves our work. However due to some network issues the work might not get saved properly. If the work is not saved then Colabo issues a warning that the work has not been saved yet. Press Ctrl+S to save your work. For downloading the file follow the steps:
1. Click on file.
2. Click on download and then click on Download ipynb.
Download ipynb fileNow whenever you want to upload notebook click on Upload notebook. Then click on the ipynb file that you want to upload. After that change the runtime if required (that is first approach is used) and then execute the cells one by one.
Similar Reads
How to use gpu in google colab? Google colab is a service provided by Google for a lot of researchers and developers around the globe. It is a Jupyter Notebook-like environment in one single place without any prerequisites. It is free to use with a limited number of computer resources and engines including free access to GPUs i.e.
3 min read
Google Colab - Running ML with Low-Spec Device Learning about Machine Learning is one of the trending things nowadays. But a lot of people face difficulties, as they don't have a device, that is powerful enough, and there are also a lot of issues, arising due to inefficient systems. So, let's see, how can we overcome this using an easy solution.
3 min read
How to update Google Colab's Python version? The importance of having a current version will be covered in this article, especially for activities involving machine learning and data science. Python versions that are out-of-date or extremely old may experience a number of issues, one of which is incompatibility with recent packages. The usage
7 min read
Getting Started With Google Colab Google Colab is the short form for "Google Colabortory". It is an executable document that lets you write, run, and share code or you can think as an improved version of "Jupyter Notebook" stored in Google Drive. You might be wondering about the word "Notebook", in simple words it is just a document
6 min read
How to run Flask App on Google Colab? Flask is a web framework in python language. This means flask provides you with tools, libraries and technologies that allow you to build a web application. This web application can be some web pages, a blog, a wiki or go as big as a web-based calendar application or a machine learning webapp. Googl
2 min read