progressr: Replace 'cli' Progress Bars with 'progressr'
Henrik Bengtsson
Source:vignettes/progressr-25-replace-cli-with-progressr.md
progressr-25-replace-cli-with-progressr.RmdThe cli package is used for progress reporting by several packages, notably tidyverse packages. For instance, in purrr, you can do:
to report on progress via the cli package as
map() is iterating over the elements. Now, instead of using
the default, built-in cli progress bar, we can
customize cli to report on progress via progressr instead.
To do this, set R option cli.progress_handlers as:
options(cli.progress_handlers = "progressr")With this option set, cli will now report on
progress according to your progressr::handlers() settings.
For example, with:
will report on progress using beepr and the RStudio Console progress panel.
To make cli report via progressr in
all your R session, set the above R option in your
~/.Rprofile startup file, e.g.
if (requireNamespace("progressr", quietly = TRUE)) {
options(cli.progress_handlers = "progressr")
}Note: A cli progress bar can have a “name”,
which can be specfied in purrr function via argument
.progress, e.g. .progress = "processing". This
name is then displayed in front of the progress bar. However, because
the progressr framework does not have a concept of
progress “name”, they are silently ignored when using
options(cli.progress_handlers = "progressr").