Become an expert in R — Interactive courses, Cheat Sheets, certificates and more!
Get Started for Free

cell-specification

Specify cells


Description

Many functions in googlesheets4 use a range argument to target specific cells. The Sheets v4 API expects user-specified ranges to be expressed via its A1 notation, but googlesheets4 accepts and converts a few alternative specifications provided by the functions in the cellranger package. Of course, you can always provide A1-style ranges directly to functions like read_sheet() or range_read_cells(). Why would you use the cellranger helpers? Some ranges are practically impossible to express in A1 notation, specifically when you want to describe rectangles with some bounds that are specified and others determined by the data.

Examples

if (gs4_has_token() && interactive()) {
  ss <- gs4_example("mini-gap")

  # Specify only the rows or only the columns
  read_sheet(ss, range = cell_rows(1:3))
  read_sheet(ss, range = cell_cols("C:D"))
  read_sheet(ss, range = cell_cols(1))

  # Specify upper or lower bound on row or column
  read_sheet(ss, range = cell_rows(c(NA, 4)))
  read_sheet(ss, range = cell_cols(c(NA, "D")))
  read_sheet(ss, range = cell_rows(c(3, NA)))
  read_sheet(ss, range = cell_cols(c(2, NA)))
  read_sheet(ss, range = cell_cols(c("C", NA)))

  # Specify a partially open rectangle
  read_sheet(ss, range = cell_limits(c(2, 3), c(NA, NA)), col_names = FALSE)
  read_sheet(ss, range = cell_limits(c(1, 2), c(NA, 4)))
}

googlesheets4

Access Google Sheets using the Sheets API V4

v0.3.0
MIT + file LICENSE
Authors
Jennifer Bryan [cre, aut] (<https://orcid.org/0000-0002-6983-2759>), RStudio [cph, fnd]
Initial release

We don't support your browser anymore

Please choose more modern alternatives, such as Google Chrome or Mozilla Firefox.