pushBackupFile {R.utils} | R Documentation |
Appends 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.
## Default S3 method: pushBackupFile(filename, path=NULL, suffix=".bak", isFile=TRUE, onMissing=c("ignore", "error"), copy=FALSE, overwrite=TRUE, ..., verbose=FALSE)
filename |
The filename of the file to backup. |
path |
The path of the file. |
suffix |
The suffix to be appended. |
isFile |
If |
onMissing |
A |
copy |
If |
overwrite |
If |
... |
Not used. |
verbose |
Returns the pathname with the suffix appended.
Henrik Bengtsson
# Create a file pathname <- "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); # Restore main file from backup pathnameR <- popBackupFile(pathnameB, verbose=TRUE); print(pathnameR); # - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - # (b) Backup, create a new file and frop backup file # - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - # Turn it into a backup file pathnameB <- pushBackupFile(pathname, verbose=TRUE); print(pathnameB); # 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);