popBackupFile
(), this method is useful
for creating a backup of a file and restoring it.## S3 method for class 'default':
pushBackupFile(filename, path=NULL, suffix=".bak", isFile=TRUE, onMissing=c("ignore", "error"), copy=FALSE, overwrite=TRUE, ..., verbose=FALSE)
character
string specifying what to do if the
file does not exist.TRUE
, an existing original file remains after
creating the backup copy, otherwise it is dropped.TRUE
, any existing backup files are overwritten,
otherwise an exception is thrown.popBackupFile
().# Create a file
pathname <- "foobar.txt";
cat(file=pathname, "File v1
");
# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
# (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
");
# Drop backup because a new main file was successfully created
pathnameR <- popBackupFile(pathnameB, verbose=TRUE);
print(pathnameR);
Run the code above in your browser using DataLab