Description Usage Arguments Details Functions
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.
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)
|
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). |
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. savepointr
s 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).
current_savepoint
: Return the current savepoint, if any.
has_current_savepoint
: Whether a current savepoint exists, TRUE/FALSE.
clear_savepointr
: Clear the current savepoint, if any, and any failed
saves.
save_current
: Create a new savepoint.
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.