A crash-resilient wrapper for batch processing that silently caches progress at defined intervals and interactively recovers from interrupted sessions.
Value
A list of successfully processed results, or an invisible list with
status = "cancelled" if aborted during resumption.
Details
The function provides a safety layer for long-running batch operations:
Checks for an existing `.rds` checkpoint file. If found, it prompts the user to resume from the last saved index or restart the process.
Prompts the user for a save frequency (e.g., every 100 items).
Executes the `target_func` on each item in `items` within a `tryCatch` block.
If a critical error occurs, it immediately saves the current state to the `checkpoint_file` and halts execution.
Periodically saves the state based on the specified frequency.
Upon successful completion of all items, the temporary checkpoint file is deleted.
Warning
This function modifies files on disk or the global environment. Please ensure you have a backup or are using version control (e.g., Git) before execution.
Examples
if (interactive()) {
dispatch_checkpoints(items = list(), target_func = print)
}
