How to read Google Sheets data into R

Manpreet Singh
3 min readApr 20, 2021

Welcome back! Yesterday we talked about the powerful GoogleSheets4 package within R, this allows you to communicate with Google Sheets from your R environment. In this tutorial i’ll break down exactly how to read data from your Google Sheets account into your R environment, let’s get started!

Installation

First off, we want to install the Google Sheets 4 package, to do this, use the following installation line inside of your R console:

install.packages("googlesheets4")

Developing The Code

Awesome, next up we want to import that library into our environment, to do so, use the following line:

#IMPORTING THE LIBRARY
library(googlesheets4)

Next up we want to essentially read the Google Sheet into our enviornment, we have a couple of ways to read it in, we can use the URL of the Google Sheet just like below:

read_sheet("https://docs.google.com/spreadsheets/d/1U6Cf_qEOhiR9AZqTqS3mbMF3zt2db48ZP5v3rkrAEJY/edit#gid=780868077")

You will essentially get a little prompt in our R console which allows you to give access from your Google Account to the API:

A little hard to read, but just follow the prompts and you’ll be good to go. Next up, you…

--

--