1515# ' classes to be captured and relayed at the end after any captured
1616# ' standard output is relayed.
1717# '
18+ # ' @param interval (numeric) The minimum time (in seconds) between
19+ # ' successive progression updates from handlers.
20+ # '
1821# ' @return Return nothing (reserved for future usage).
1922# '
2023# ' @example incl/with_progress.R
2124# '
2225# ' @export
23- with_progress <- function (expr , handlers = getOption(" progressr.handlers" , txtprogressbar_handler()) , cleanup = TRUE , delay_stdout = getOption(" progressr.delay_stdout" , interactive()), delay_conditions = getOption(" progressr.delay_conditions" , if (interactive()) c(" condition" ) else character (0L ))) {
26+ with_progress <- function (expr , handlers = getOption(" progressr.handlers" , txtprogressbar_handler ) , cleanup = TRUE , delay_stdout = getOption(" progressr.delay_stdout" , interactive()), delay_conditions = getOption(" progressr.delay_conditions" , if (interactive()) c(" condition" ) else character (0L )), interval = NULL ) {
2427 stop_if_not(is.logical(cleanup ), length(cleanup ) == 1L , ! is.na(cleanup ))
2528
2629 # # FIXME: With zero handlers, progression conditions will be
2730 # # passed on upstream just as without with_progress().
2831 # # Is that what we want? /HB 2019-05-17
2932 if (length(handlers ) == 0L ) return (expr )
3033 if (! is.list(handlers )) handlers <- list (handlers )
31-
34+
35+ # # Temporarily set progressr options
36+ if (! is.null(interval )) {
37+ stop_if_not(is.numeric(interval ), length(interval ) == 1L , ! is.na(interval ))
38+ oopts <- options(progressr.interval = interval )
39+ on.exit(options(oopts ))
40+ }
41+
3242 for (kk in seq_along(handlers )) {
3343 handler <- handlers [[kk ]]
3444 stopifnot(is.function(handler ))
@@ -63,7 +73,7 @@ with_progress <- function(expr, handlers = getOption("progressr.handlers", txtpr
6373 signalCondition(control_progression(" shutdown" , status = status ))
6474 }, muffleProgression = function (p ) NULL )
6575 }, progression = handler )
66- })
76+ }, add = TRUE )
6777 }
6878
6979 # # Captured stdout output and conditions
@@ -79,7 +89,7 @@ with_progress <- function(expr, handlers = getOption("progressr.handlers", txtpr
7989 stdout <- rawToChar(rawConnectionValue(stdout_file ))
8090 close(stdout_file )
8191 if (length(stdout ) > 0 ) cat(stdout , file = stdout())
82- })
92+ }, add = TRUE )
8393 }
8494
8595 # # Delay conditions?
0 commit comments