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

gs_grepdel

Delete several spreadsheets at once by title


Description

These functions violate the general convention of operating on a registered Google sheet, i.e. on a googlesheet object. But the need to delete a bunch of sheets at once, based on a vector of titles or on a regular expression, came up so much during development and testing, that it seemed wise to package this as a function.

Usage

gs_grepdel(regex, ..., verbose = TRUE)

gs_vecdel(vec, verbose = TRUE)

Arguments

regex

character; a regular expression; sheets whose titles match will be deleted

...

optional arguments to be passed to grep when matching regex to sheet titles

verbose

logical; do you want informative messages?

vec

character vector of sheet titles to delete

See Also

gs_delete for more detail on what you can and cannot delete and how to recover from accidental deletion

Other sheet deletion functions: gs_delete

Examples

## Not run: 
sheet_title <- c("cat", "catherine", "tomCAT", "abdicate", "FLYCATCHER")
ss <- lapply(paste0("TEST-", sheet_title), gs_new)
# list, for safety!, then delete 'TEST-abdicate' and 'TEST-catherine'
gs_ls(regex = "TEST-[a-zA-Z]*cat[a-zA-Z]+$")
gs_grepdel(regex = "TEST-[a-zA-Z]*cat[a-zA-Z]+$")

# list, for safety!, then delete the rest,
# i.e. 'TEST-cat', 'TEST-tomCAT', and 'TEST-FLYCATCHER'
gs_ls(regex = "TEST-[a-zA-Z]*cat[a-zA-Z]*$", ignore.case = TRUE)
gs_grepdel(regex = "TEST-[a-zA-Z]*cat[a-zA-Z]*$", ignore.case = TRUE)

## using gs_vecdel()
sheet_title <- c("cat", "catherine", "tomCAT", "abdicate", "FLYCATCHER")
ss <- lapply(paste0("TEST-", sheet_title), gs_new)
# delete two of these sheets
gs_vecdel(c("TEST-cat", "TEST-abdicate"))
# see? they are really gone, but the others remain
gs_ls(regex = "TEST-[a-zA-Z]*cat[a-zA-Z]*$", ignore.case = TRUE)
# delete the remainder
gs_vecdel(c("TEST-FLYCATCHER", "TEST-tomCAT", "TEST-catherine"))
# see? they are all gone now
gs_ls(regex = "TEST-[a-zA-Z]*cat[a-zA-Z]*$", ignore.case = TRUE)

## End(Not run)

googlesheets

Manage Google Spreadsheets from R

v0.3.0
MIT + file LICENSE
Authors
Jennifer Bryan [aut, cre], Joanna Zhao [aut]
Initial release

We don't support your browser anymore

Please choose more modern alternatives, such as Google Chrome or Mozilla Firefox.