pushBackupFile.RdAppends a backup suffix to the pathname and, optionally, renames an existing file accordingly.
In combination with popBackupFile(), this method is useful
for creating a backup of a file and restoring it.
# S3 method for default
pushBackupFile(filename, path=NULL, suffix=".bak", isFile=TRUE,
onMissing=c("ignore", "error"), copy=FALSE, overwrite=TRUE, ..., verbose=FALSE)The filename of the file to backup.
The path of the file.
The suffix to be appended.
If TRUE, the file must exist and will be renamed
on the file system. If FALSE, it is only the pathname string
that will be modified. For details, see below.
A character string specifying what to do if the
file does not exist.
If TRUE, an existing original file remains after
creating the backup copy, otherwise it is dropped.
If TRUE, any existing backup files are overwritten,
otherwise an exception is thrown.
Not used.
Returns the pathname with the suffix appended.
# Create a file
pathname <- file.path(tempdir(), "foobar.txt")
cat(file=pathname, "File v1\n")
# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
# (a) Backup and restore a file
# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
# Turn it into a backup file
pathnameB <- pushBackupFile(pathname, verbose=TRUE)
print(pathnameB)
#> [1] "/tmp/henrik/RtmpAr1qq8/foobar.txt.bak"
# Restore main file from backup
pathnameR <- popBackupFile(pathnameB, verbose=TRUE)
print(pathnameR)
#> [1] "/tmp/henrik/RtmpAr1qq8/foobar.txt"
# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
# (b) Backup, create a new file and frop backup file
# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
# Turn it into a backup file
pathnameB <- pushBackupFile(pathname, verbose=TRUE)
print(pathnameB)
#> [1] "/tmp/henrik/RtmpAr1qq8/foobar.txt.bak"
# Create a new file
cat(file=pathname, "File v2\n")
# Drop backup because a new main file was successfully created
pathnameR <- popBackupFile(pathnameB, verbose=TRUE)
print(pathnameR)
#> [1] "/tmp/henrik/RtmpAr1qq8/foobar.txt"