savepointr: savepointr

Description Usage Arguments Details Functions

Description

A savepointr is a pointer to a 'savepoint'. A savepoint is an R object, saved to disk, which represents the state of a long running process. For example, if you are running an iterative optimisation procedure, you could use a savepoint to store the most recently found solution. Then, if the R crashes for some reason, the process can be restarted from the last savepoint.

Usage

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
savepointr(directory = ".", create_directory = TRUE,
  current_path = file.path(directory, "savepoint.rds"),
  new_path = file.path(directory, "new_savepoint.rds"))

current_savepoint(sptr)

has_current_savepoint(sptr)

clear_savepointr(sptr)

save_current(sptr, savepoint)

Arguments

directory

The directory in which to store the savepoint. Ignored if current_path and new_path are provided.

create_directory

If TRUE, and directory is not ignored, will create the directory if it does not yet exist.

current_path

Path at which the current savepoint will be stored. Regardless of the file extension, will be stored in RDS format.

new_path

Path where new savepoints will initially be saved, before being safely renamed over the current path.

sptr

A savepointr object.

savepoint

An arbitrary R object (must be serializable).

Details

It is not particularly hard to implement a savepoint mechanism manually, by saving out the current state of the computation from time to time, perhaps using saveRDS. This can be dangerous if done naively, since the computer could crash while conducting the save, which could leave the savepoint in an unrecoverable state. savepointrs avoid this by using safe_saveRDS to perform the save.

savepointr creates a savepointr object. Called with no arguments, the savepointr will reside in the current directory. Alternatively, either a directory can be specified, or the paths to use for the safe_saveRDS mechanism can be specified directly.

current_savepoint returns the value of the current savepoint, or NULL if you haven't saved anything yet. This function reads from disk, and therefore should not be called too often or it may slow down your program.

has_current_savepoint checks whether the savepoint has ever been saved before, returning TRUE or FALSE for yes or no, respectively.

clear_savepointr resets the savepoint, clearing any files - this is destructive, so use it carefully.

Finally, save_current is used to update the savepoint. It can save any R object for which saveRDS works, so integers, vectors, lists, are all acceptable objects. This method is guaranteed to either succeed, updating the savepoint, or fail, leaving the current savepoint unchanged (though see safe_saveRDS for details/caveats on this guarantee).

Functions


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