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

sheet_append

Append rows to a sheet


Description

Adds one or more new rows after the last row with data in a (work)sheet, increasing the row dimension of the sheet if necessary.

Usage

sheet_append(ss, data, sheet = 1)

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().

data

A data frame.

sheet

Sheet to append to, in the sense of "worksheet" or "tab". You can identify a sheet by name, with a string, or by position, with a number.

Value

The input ss, as an instance of sheets_id

See Also

Makes an AppendCellsRequest:

Other write functions: gs4_create(), gs4_formula(), range_delete(), range_flood(), range_write(), sheet_write()

Examples

if (gs4_has_token()) {
  # we will recreate the table of "other" deaths from this example Sheet
  (deaths <- gs4_example("deaths") %>%
    range_read(range = "other_data", col_types = "????DD"))

  # split the data into 3 pieces, which we will send separately
  deaths_one   <- deaths[ 1:5, ]
  deaths_two   <- deaths[   6, ]
  deaths_three <- deaths[7:10, ]

  # create a Sheet and send the first chunk of data
  ss <- gs4_create("sheet-append-demo", sheets = list(deaths = deaths_one))

  # append a single row
  ss %>% sheet_append(deaths_two)

  # append remaining rows
  ss %>% sheet_append(deaths_three)

  # read and check against the original
  deaths_replica <- range_read(ss, col_types = "????DD")
  identical(deaths, deaths_replica)

  # clean up
  gs4_find("sheet-append-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.