Copy a (work)sheetSource:
Copies a (work)sheet, within its current (spread)Sheet or to another Sheet.
sheet_copy( from_ss, from_sheet = NULL, to_ss = from_ss, to_sheet = NULL, .before = NULL, .after = NULL )
Something that identifies a Google Sheet:
its file id as a string or
a URL from which we can recover the id
dribble, which is how googledrive represents Drive files
an instance of
googlesheets4_spreadsheet, which is what
Sheet to copy, in the sense of "worksheet" or "tab". You can identify a sheet by name, with a string, or by position, with a number. Defaults to the first visible sheet.
The Sheet to copy to. Accepts all the same types of input as
from_ss, which is also what this defaults to, if unspecified.
Optional. Name of the new sheet, as a string. If you don't specify this, Google generates a name, along the lines of "Copy of blah". Note that sheet names must be unique within a Sheet, so if the automatic name would violate this, Google also de-duplicates it for you, meaning you could conceivably end up with "Copy of blah 2". If you have better ideas about sheet names, specify
- .before, .after
Optional specification of where to put the new sheet. Specify, at most, one of
.after. Refer to an existing sheet by name (via a string) or by position (via a number). If unspecified, Sheets puts the new sheet at the end.
The receiving Sheet,
to_ ss, as an instance of
If the copy happens within one Sheet, makes a
If the copy is from one Sheet to another, wraps the
and possibly makes a subsequent
ss_aaa <- gs4_create( "sheet-copy-demo-aaa", sheets = list(mtcars = head(mtcars), chickwts = head(chickwts)) ) #> ✔ Creating new Sheet: sheet-copy-demo-aaa. # copy 'mtcars' sheet within existing Sheet, accept autogenerated name ss_aaa %>% sheet_copy() #> ✔ Duplicating sheet mtcars in sheet-copy-demo-aaa. #> ✔ Copied as Copy of mtcars. # copy 'mtcars' sheet within existing Sheet # specify new sheet's name and location ss_aaa %>% sheet_copy(to_sheet = "mtcars-the-sequel", .after = 1) #> ✔ Duplicating sheet Copy of mtcars in sheet-copy-demo-aaa. #> ✔ Copied as mtcars-the-sequel. # make a second Sheet ss_bbb <- gs4_create("sheet-copy-demo-bbb") #> ✔ Creating new Sheet: sheet-copy-demo-bbb. # copy 'chickwts' sheet from first Sheet to second # accept auto-generated name and default location ss_aaa %>% sheet_copy("chickwts", to_ss = ss_bbb) #> ✔ Copying sheet chickwts from sheet-copy-demo-aaa to sheet-copy-demo-bbb. #> ✔ Copied as Copy of chickwts. # copy 'chickwts' sheet from first Sheet to second, # WITH a specific name and into a specific location ss_aaa %>% sheet_copy( "chickwts", to_ss = ss_bbb, to_sheet = "chicks-two", .before = 1 ) #> ✔ Copying sheet chickwts from sheet-copy-demo-aaa to sheet-copy-demo-bbb. #> ✔ Copied as chicks-two. # clean up gs4_find("sheet-copy-demo") %>% googledrive::drive_trash() #> Files trashed: #> • sheet-copy-demo-bbb <id: 1fqP9LI_GqP2moE0wvn6Nq7hFc5SvcWf2kN2lmMmbV7k> #> • sheet-copy-demo-aaa <id: 19K3P5BHZ2p9xyiTh1shXyAtAQYT2hbOLJMRnYJZ42_g>