Learn R Programming

googlesheets4 (version 0.1.0)

sheets_cells: Read cells from a Sheet

Description

This low-level function returns cell data in a tibble with 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. sheets_read(), is what most users are looking for. It is basically sheets_cells() (this function), followed by spread_sheet(), which looks after reshaping and column typing. But if you want the raw data from the API, use sheets_cells().

Usage

sheets_cells(ss, sheet = NULL, range = NULL, skip = 0, n_max = Inf)

Arguments

ss

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

sheet

Sheet to read, as in "worksheet" or "tab". Either a string (the name of a sheet), or an integer (the position of the sheet). 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.

Value

A tibble with one row per non-empty cell in the range.

Examples

Run this code
# NOT RUN {
if (sheets_has_token()) {
  sheets_cells(sheets_example("deaths"), range = "arts_data")

  sheets_example("cell-contents-and-formats") %>%
    sheets_cells(range = "types!A2:A5")
}
# }

Run the code above in your browser using DataLab