Experimental lifecycle

Writes a data frame into a (work)sheet inside a (spread)Sheet. The target sheet is styled as a table:

  • Special formatting is applied to the header row, which holds column names.

  • The first row (header row) is frozen.

  • Sheet dimensions are set to "shrink wrap" the data.

If no existing Sheet is specified via ss, this function delegates to sheets_create() and the new Sheet's name is randomly generated. If that's undesirable, call sheets_create() directly to get more control.

If no sheet is specified or if sheet doesn't identify an existing sheet, a new sheet is added to receive the data. If sheet specifies an existing sheet, it is effectively overwritten! All pre-existing values, formats, and dimensions are cleared and the targeted sheet gets new values and dimensions from data.

write_sheet(data, ss = NULL, sheet = NULL)

sheets_write(data, ss = NULL, sheet = NULL)



A data frame. If it has zero rows, we send one empty pseudo-row of data, so that we can apply the usual table styling. This empty row goes away (gets filled, actually) the first time you send more data with sheets_append().


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 sheets_get()), or a dribble, which is how googledrive represents Drive files. Processed through as_sheets_id().


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


The input ss, as an instance of sheets_id

See also


if (sheets_has_token()) { df <- data.frame( x = 1:3, y = letters[1:3] ) # specify only a data frame, get a new Sheet, with a random name ss <- sheets_write(df) sheets_read(ss) # clean up googledrive::drive_rm(ss) # create a Sheet with some initial, placeholder data ss <- sheets_create( "sheets-write-demo", sheets = list(alpha = data.frame(x = 1), omega = data.frame(x = 1)) ) # write df into its own, new sheet sheets_write(df, ss = ss) # write mtcars into the sheet named "omega" sheets_write(mtcars, ss = ss, sheet = "omega") # get an overview of the sheets sheets_sheet_properties(ss) # view your magnificent creation in the browser # sheets_browse(ss) # clean up googledrive::drive_rm(ss) }
#> Creating new Sheet: "smooth-indianabat"
#> Reading from "smooth-indianabat"
#> Range "df"
#> Files deleted: #> * smooth-indianabat: 1ivGG5pQhKZwvf-ZzlvKz-o4wFYXgHcet5noLKo05C1E
#> Creating new Sheet: "sheets-write-demo"
#> Writing to "sheets-write-demo"
#> Writing to sheet "df"
#> Writing to "sheets-write-demo"
#> Writing to sheet "omega"
#> Files deleted: #> * sheets-write-demo: 1tN-mMlMfYfmzBGaFJEOv2NsUywELHSLGxC3P44v1jfs