pushBackupFile
From R.utils v1.32.4
by Henrik Bengtsson
Appends a backup suffix to the pathname
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.
- Keywords
- utilities, programming, IO
Usage
## S3 method for class 'default':
pushBackupFile(filename, path=NULL, suffix=".bak", isFile=TRUE,
onMissing=c("ignore", "error"), copy=FALSE, overwrite=TRUE, ..., verbose=FALSE)
Arguments
- filename
- The filename of the file to backup.
- path
- The path of the file.
- suffix
- The suffix to be appended.
- isFile
- If
TRUE
, the file must exist and will be renamed on the file system. IfFALSE
, it is only the pathname string that will be mo - onMissing
- A
character
string specifying what to do if the file does not exist. - copy
- If
TRUE
, an existing original file remains after creating the backup copy, otherwise it is dropped. - overwrite
- If
TRUE
, any existing backup files are overwritten, otherwise an exception is thrown. - ...
- Not used.
- verbose
- A
logical
orVerbose
.
Value
- Returns the pathname with the suffix appended.
See Also
Examples
# 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);
Community examples
Looks like there are no examples yet.