20.13 Reading Google Sheets

- The first argument to read_sheet() is the URL of the file to read, and it returns a tibble:

students_url <- "https://docs.google.com/spreadsheets/d/1V1nPp1tzOuutXFLb3G9Eyxi3qxeEhnOXUzL5_BcCQ0w"

students <- read_sheet(students_url)
students <- read_sheet(
  col_names = c("student_id", "full_name", "favourite_food", "meal_plan", "age"),
  skip = 1,
  na = c("", "N/A"),
  col_types = "dcccc"
  • Note that we defined column types a bit differently here, using short codes. For example, “dcccc” stands for “double, character, character, character, character”.
penguins_url <- "https://docs.google.com/spreadsheets/d/1aFu8lnD_g0yjF5O-K6SFgSEWiHPpgvFCF0NY9D6LXnY"

read_sheet(penguins_url, sheet = "Torgersen Island")

We can obtain a list of all sheets within a Google Sheet with sheet_names():

  • Reading in a portion of the sheet
deaths_url <- gs4_example("deaths")

deaths <- read_sheet(deaths_url, range = "A5:F15")