Scans an output directory for files matching the pattern
<file_prefix>_year<XXXX>.<ext> (e.g. cohortData_year2920.rds) and
returns the furthest simulation year reached, the wall-clock elapsed time
since the first checkpoint, and a percentage-complete estimate.
get_sim_year_heartbeat(
output_path,
start_year = NULL,
end_year = NULL,
file_prefix = "cohortData"
)Character. Directory to scan for checkpoint files.
Integer or NULL. Expected start year of the simulation.
If NULL (default), inferred as the minimum year found in output_path.
Integer or NULL. Expected end year.
If NULL (default), inferred as the maximum year found in output_path
(i.e. 100 % is reported only once the final checkpoint exists).
Supply a value (e.g. 3020L) to get a meaningful percentage before the
run completes.
Character. Only files whose basename begins with this
prefix are used as checkpoint indicators. Defaults to "cohortData"
because that file is written after all others at each SpaDES save
event, making it the most reliable completion signal.
A named list with elements:
tsCharacter. Modification timestamp of the latest checkpoint file.
iterInteger. Simulation year of the latest checkpoint.
startedCharacter. Modification timestamp of the first checkpoint file.
elapseddifftime. Wall-clock time between first and latest checkpoint.
pct_completeNumeric 0-100. Percentage of the simulation completed,
or NA if start_year == end_year.
All elements are NA / NA_character_ when no matching files are found.
if (FALSE) { # \dontrun{
hb <- get_sim_year_heartbeat(
output_path = "outputs/6.5/1991-2020/NRV_ssp370/rep1",
end_year = 3020L
)
message("Year: ", hb$iter, " (", hb$pct_complete, "%) -- last checkpoint: ", hb$ts)
} # }