I'm trying to gain some control over when graphic objects are being saved and stumbled across this related post from 8+ years ago: https://stackoverflow.com/a/1541872/5322644
I'd like to come up with a more general approach and below is my current attempt. Of course, it doesn't work and so I'd appreciate some help on it.
## safely avoid overwriting files when saving objects using a user specified save.function
safeSave <- function(save.function = save, ..., file=stop("'file' must be specified"), overwrite=FALSE ) {
if ( file.exists(file) & !overwrite ) stop("'file' already exists")
do.call(save.function, as.list( ..., file = file))
}
## Try using function.
## It appears to be trying to save the value of `tmp` rather than the variable `tmp`
tmp = 10
safeSave(save, tmp, file = "tmp.Rda")
# Error in (function (..., list = character(), file = stop("'file' must be specified"), : object ‘10’ not found