Creates a local backup of a Google Sheet. It is accessed via googlesheets4::read_sheet()
and written via
readr::write_csv()
or writexl::write_xlsx()
, depending on the file extension of path
.
Usage
backup_g_sheet(
g_id,
path,
...,
path_gcp_service_account_key = Sys.getenv("PATH_GCP_KEY_ZDA"),
overwrite = TRUE,
force = FALSE,
quiet = TRUE
)
Arguments
- g_id
Google Drive file ID. A character scalar.
- path
Path to the local file backup destination. A character scalar.
- ...
Further arguments passed on to
googlesheets4::read_sheet()
.- path_gcp_service_account_key
Path to the GCP Service Account Key JSON file. See
auth_g_drive_gcp()
for details.- overwrite
Whether or not to overwrite an already existing file under
path
.- force
Whether or not to force overwriting the file regardless whether it has changed since the last backup or not.
- quiet
Whether or not to suppress printing status output from googledrive and googlesheets4 operations.
Value
A tibble if the local backup was (over)written, otherwise NULL
, meaning the remote file hasn't deviated from the local backup
since the last run, invisibly.
Details
backup_g_sheet()
only backs up a single worksheet at once (specified by the optional sheet
argument). If you intend to backup multiple worksheets of the
same Google Sheet, consider using backup_g_file()
in combination with a file type
that supports multiple worksheets like "ods"
or "xlsx"
.
See also
Other Google Apps functions:
auth_g_drive_gcp()
,
auth_g_sheets_gcp()
,
backup_g_file()
,
g_file_mod_time()
,
upload_to_g_drive()