How to Use R in Google Colab (2026 Update)
Greetings, humanists, social and data scientists!
Ever imagined a world where any computer with an internet browser could be your playground for programming in R? As cloud computing dominates data science in 2026, this is your reality! Google Colab enables you to execute R code with remarkable ease, completely eliminating the need for complex local installations. The cherry on top? It’s free and allows seamless sharing and collaboration on your projects.
⚡Quick Answer: How to Run R in Google Colab?
If you are in a hurry, here is the short version of how to get R running in your Colab notebook:
- Open a new Google Colab notebook.
- Go to the top menu and click on Runtime.
- Select Change runtime type.
- Under the Runtime type dropdown, change it from Python 3 to R.
- Click Save. You are ready to code!
In this lesson, I will walk you through the details of using R in Google Colab and provide a hands-on code example exploring the popularity of baby names over the last century. Don’t forget to check out the step-by-step tutorial in the video below!
1. Step-by-Step: Setting the R Runtime in Colab
It is incredibly straightforward to configure Google Colab to accept R code. By default, Colab notebooks spin up Python environments. All you have to do is change the runtime type.
In the top navigation menu, click on Runtime, then choose the option Change Runtime Type. Select R from the dropdown menu, as shown in the figure below. That’s all it takes!

2. The Data Source: Historical Baby Names
The data used in our hands-on tutorial comes from the babynames package. It contains a comprehensive dataset with baby names registered between 1880 and 2017 in the United States. For further details on the structure of the data, please explore the official documentation of the package here.
3. Hands-On Example: Coding with R in Google Colab
Below you will find the R code used in the video tutorial. Paste this into a Colab code block. Feel free to copy, test, and change the parameters—for example, try searching for your own name!
content_copy Copy
# Install the necessary package directly in the Colab cell
install.packages("babynames")
# Load the library
library(babynames)
# Inspect the structure of the dataset
str(babynames)
# Filter the dataset for a specific name
bruno_df <- babynames[babynames$name == "Bruno", ]
# Plot the historical popularity of the name
plot(x = bruno_df$year,
y = bruno_df$n,
type = "l",
main = "Historical Popularity of the Name Bruno in the US",
xlab = "Year",
ylab = "Number of Babies")The R code in above accomplishes the following:
- Setup: It installs and loads the babynames package, which contains the historical dataset.
- Inspection: It uses the str() function to let you inspect the internal structure of the dataset.
- Filtering: It filters the massive dataset to isolate the records specifically for your name, saving them into a new data frame (bruno_df).
- Visualization: It generates a line plot (type = “l”) with the years on the x-axis and the number of babies on the y-axis, effectively showing how the popularity of the name has fluctuated over time.

4. Frequently Asked Questions (FAQ)
Is R completely free to use on Google Colab? Yes, the standard tier of Google Colab is entirely free and supports R programming.
Can I install any CRAN package in Colab? Yes! You can use the standard install.packages("package_name") command just like you would in RStudio.
Can I read local CSV files into Colab using R? Yes, you can upload files directly to the temporary session storage using the folder icon on the left sidebar, or you can mount your Google Drive to read datasets directly from your cloud storage.
5. Conclusions
- Google Colab provides a hassle-free, browser-based journey into the world of R programming and data exploration.
- With a quick toggle in the runtime menu, a Python environment instantly transforms to process R code.
- Mastering the use of R within Google Colab not only enriches your data analysis workflows but paves the way for enhanced, hardware-accelerated collaborative computing in the cloud.
Leave any questions or concerns you might have in the comments below!
Comments
There are currently no comments on this article, be the first to add one below
Add a Comment
If you are looking for a response to your comment, either leave your email address or check back on this page periodically.