safe_saveRDS: Save an RDS file in a fault-tolerant manner

Description Usage Arguments

Description

Calls saveRDS in a fault-tolerant manner, such that if the save fails, the existing file will not be overwritten. This is done with the following scheme:

  1. Call saveRDS to save the file to via_filename.

  2. If that succeeds, call file.rename to rename the new file to overwrite filename.

The underlying implementation of file.rename uses the POSIX function rename, which has the guarantee that it either succeeds or leaves the destination file untouched (subject to hardware limitations). Therefore, this function also either succeeds, or leaves filename untouched. In reality, this guarantee is almost certainly dependent on the operating system, the file system, and a host of other factors. Still, even if the guarantee is not fully satisfied, renaming the file ought to be faster and therefore a system failure during the rename is less likely than during saveRDS.

Usage

1
safe_saveRDS(object, filename, via_filename, ...)

Arguments

object

R object to serialize.

filename

Destination filename. Unlike saveRDS, this can't be a connection.

via_filename

Filename to save the file to before the rename step. This should probably be on the same filesystem as filename to get the atomicity guarantee described above.

...

Passed to saveRDS.


mbertolacci/savepointr documentation built on May 13, 2019, 4:06 a.m.