Preventing overwriting of files when using save() or save.image()
file, r
Solution
Use `file.exists()` to test if the file is there, and if it is, append a string to the name.
Edit:
Thanks Marek, I'll expand on your idea a bit... he could add this to deal with both `save()` and `save.image()`
SafeSave <- function( ..., file=stop("'file' must be specified"), overwrite=FALSE, save.fun=save) {
if ( file.exists(file) & !overwrite ) stop("'file' already exists")
save.fun(..., file=file)
}
I would not overwrite save... if `source()` was used in a REPL session, users may not be aware of the function overwrite.
Problem
I am trying to find a way to stop accidental overwriting of files when using the save() and save.image() function in R.