View source: R/save_rds_archive.R
save_rds_archive | R Documentation |
This wrapper around base R saveRDS()
checks if the file
you attempt to save already exists. If it does, the existing file is
renamed / archived (with a time stamp), and the "updated" file will be
saved under the specified name. This means that existing code which depends
on the file name remaining constant (e.g., readRDS()
calls in other
scripts) will continue to work while an archived copy of the - otherwise
overwritten - file will be kept.
Please note: If the file does not already exist (i.e., if there is
nothing to overwrite or archive), regular saveRDS
behavior will be invoked. In such a case, all arguments except
object
and file
will be ignored!
save_rds_archive(
object,
file = "",
archive = TRUE,
last_modified = FALSE,
with_time = FALSE,
archive_dir_path = NULL,
...
)
object |
Object to be saved |
file |
Name of the file (path) where the R object is saved to. Note that
this wrapper function does currently not support |
archive |
Logical - should the file be archived if it already exists (default), or should it be overwritten (regular saveRDS behavior)? |
last_modified |
Logical - should the file name of the archived file be
appended with the "last modified" date/time of the original RDS
instead of the current date/time? Defaults to |
with_time |
Logical - should the file be archived with just a date
suffix (default) or with a date and time suffix? Applies to both
archiving and modification date. Set to |
archive_dir_path |
Character - if desired, path to a dedicated archive
(sub-)directory (relative to the directory of |
... |
Additional arguments passed along to |
CAUTION: Note that existing archived versions of files will
still be overwritten if they have the same archived file name, i.e.,
archived files will not be archived. This usually happens when you use only
the date suffix and call this function multiple times per day: Only the
most recent archived version will be kept. If you want to keep multiple
archived versions of a single file, set with_time
to TRUE
.
This will append a time stamp to the archived file name up to the current
second (virtually ruling out the possibility of duplicated file names).
NULL
(invisibly)
Lukas Feick
saveRDS
## Not run:
x <- 5
y <- 10
z <- 20
## save to RDS
saveRDS(x, "temp.RDS")
saveRDS(y, "temp.RDS")
## "temp.RDS" is silently overwritten with y
## previous version is lost
readRDS("temp.RDS")
#> [1] 10
save_rds_archive(z, "temp.RDS")
## current version is updated
readRDS("temp.RDS")
#> [1] 20
## previous version is archived
readRDS("temp_ARCHIVED_on_2020-03-30.RDS")
#> [1] 10
## End(Not run)
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.