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

sheet_resize

Change the size of a (work)sheet


Description

Changes the number of rows and/or columns in a (work)sheet.

Usage

sheet_resize(ss, sheet = NULL, nrow = NULL, ncol = NULL, exact = FALSE)

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 resize, in the sense of "worksheet" or "tab". You can identify a sheet by name, with a string, or by position, with a number.

nrow, ncol

Desired number of rows or columns, respectively. The default of NULL means to leave unchanged.

exact

Logical, indicating whether to impose nrow and ncol exactly or to treat them as lower bounds. If exact = FALSE, sheet_resize() can only add cells. If exact = TRUE, cells can be deleted and their contents are lost.

Value

The input ss, as an instance of sheets_id

See Also

Makes an UpdateSheetPropertiesRequest:

  • <# https://developers.google.com/sheets/api/reference/rest/v4/spreadsheets/request#UpdateSheetPropertiesRequest>

Examples

if (gs4_has_token()) {
  # create a Sheet with the default initial worksheet
  (ss <- gs4_create("sheet-resize-demo"))

  # see (work)sheet dims
  sheet_properties(ss)

  # no resize occurs
  sheet_resize(ss, nrow = 2, ncol = 6)

  # reduce sheet size
  sheet_resize(ss, nrow = 5, ncol = 7, exact = TRUE)

  # add rows
  sheet_resize(ss, nrow = 7)

  # add columns
  sheet_resize(ss, ncol = 10)

  # add rows and columns
  sheet_resize(ss, nrow = 9, ncol = 12)

  # re-inspect (work)sheet dims
  sheet_properties(ss)

  # clean up
  gs4_find("sheet-resize-demo") %>%
    googledrive::drive_trash()
}

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.