Description
In R, at least, using handlers("cli")
provides a progress bar which provides an estimated time to completion by way of cli_progress_bar()
's default settings. This is handy and likely works well for operations taking seconds or perhaps minutes. It's awkward for things taking a couple hours, though, as cli's default format string is hard coded to call vague_dt(format = "terse")
to display the time remaining. Terse is terse, so what happens is the progress bar will sit at 2h
for up to an hour without any apparent progress, even though the percent complete's increasing, and then suddenly drop to 1h
for half an hour, after which it starts counting down minutes.
Since there doesn't seem to be a way to pass cli_progress_bar()
's format
argument via progressor()
it appears necessary to set a global cli option to use a formatting function which puts more digits in the time remaining. It took me like an hour of going through the cli documentation and source code, plus some testing, to figure out how to hook on to cli::pb_eta_raw
to do this. Capturing an example thus seemed helpful, minimally so it'll show up in searches here.
library(progressr)
handlers(global = TRUE)
handlers("cli")
options(cli.progress_format_iterator = "{cli::pb_bar} {cli::pb_percent} | iteration {cli::pb_current} of {cli::pb_total} [{cli::pb_elapsed_clock}] ETA: {prettyunits::pretty_sec(as.numeric(cli::pb_eta_raw))}") # could be simplified or changed another method of formatting pb_eta_raw
delay_loop = function()
{
progressBar = progressor(10)
for (iteration in 1:10)
{
Sys.sleep(1)
progressBar()
}
}
delay_loop()