Learn R Programming

googlesheets4 (version 0.3.0)

range_read_cells: Read cells from a Sheet

Description

This low-level function returns cell data in a tibble with one row per cell. This tibble has integer variables row and column (referring to location with the Google Sheet), an A1-style reference loc, and a cell list-column. The flagship function read_sheet(), a.k.a. range_read(), is what most users are looking for, rather than range_read_cells(). read_sheet() is basically range_read_cells() (this function), followed by spread_sheet(), which looks after reshaping and column typing. But if you really want raw cell data from the API, range_read_cells() is for you!

Usage

range_read_cells(
  ss,
  sheet = NULL,
  range = NULL,
  skip = 0,
  n_max = Inf,
  cell_data = c("default", "full"),
  discard_empty = TRUE
)

Arguments

ss

Something that identifies a Google Sheet: its file ID, a URL from which we can recover the ID, an instance of googlesheets4_spreadsheet (returned by gs4_get()), or a dribble, which is how googledrive represents Drive files. Processed through as_sheets_id().

sheet

Sheet to read, in the sense of "worksheet" or "tab". You can identify a sheet by name, with a string, or by position, with a number. Ignored if the sheet is specified via range. If neither argument specifies the sheet, defaults to the first visible sheet.

range

A cell range to read from. If NULL, all non-empty cells are read. Otherwise specify range as described in Sheets A1 notation or using the helpers documented in cell-specification. Sheets uses fairly standard spreadsheet range notation, although a bit different from Excel. Examples of valid ranges: "Sheet1!A1:B2", "Sheet1!A:A", "Sheet1!1:2", "Sheet1!A5:A", "A1:B2", "Sheet1". Interpreted strictly, even if the range forces the inclusion of leading, trailing, or embedded empty rows or columns. Takes precedence over skip, n_max and sheet. Note range can be a named range, like "sales_data", without any cell reference.

skip

Minimum number of rows to skip before reading anything, be it column names or data. Leading empty rows are automatically skipped, so this is a lower bound. Ignored if range is given.

n_max

Maximum number of data rows to parse into the returned tibble. Trailing empty rows are automatically skipped, so this is an upper bound on the number of rows in the result. Ignored if range is given. n_max is imposed locally, after reading all non-empty cells, so, if speed is an issue, it is better to use range.

cell_data

How much detail to get for each cell. "default" retrieves the fields actually used when googlesheets4 guesses or imposes cell and column types. "full" retrieves all fields in the CellData schema. The main differences relate to cell formatting.

discard_empty

Whether to discard cells that have no data. Literally, we check for an effectiveValue, which is one of the fields in the CellData schema.

Value

A tibble with one row per cell in the range.

See Also

Wraps the spreadsheets.get endpoint:

Examples

Run this code
# NOT RUN {
if (gs4_has_token()) {
  range_read_cells(gs4_example("deaths"), range = "arts_data")

  # if you want detailed and exhaustive cell data, do this
  range_read_cells(
    gs4_example("formulas-and-formats"),
    cell_data = "full",
    discard_empty = FALSE
  )
}
# }

Run the code above in your browser using DataLab