1818# ' @param interval (numeric) The minimum time (in seconds) between
1919# ' successive progression updates from handlers.
2020# '
21+ # ' @param enable (logical) If FALSE, then progress is not reported.
22+ # '
2123# ' @return Return nothing (reserved for future usage).
2224# '
2325# ' @example incl/with_progress.R
2426# '
2527# ' @export
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 ) {
28+ 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 , enable = NULL ) {
2729 stop_if_not(is.logical(cleanup ), length(cleanup ) == 1L , ! is.na(cleanup ))
2830
2931 # # FIXME: With zero handlers, progression conditions will be
@@ -33,9 +35,17 @@ with_progress <- function(expr, handlers = getOption("progressr.handlers", txtpr
3335 if (! is.list(handlers )) handlers <- list (handlers )
3436
3537 # # Temporarily set progressr options
38+ options <- list ()
3639 if (! is.null(interval )) {
3740 stop_if_not(is.numeric(interval ), length(interval ) == 1L , ! is.na(interval ))
38- oopts <- options(progressr.interval = interval )
41+ options [[" progressr.interval" ]] <- interval
42+ }
43+ if (! is.null(enable )) {
44+ stop_if_not(is.logical(enable ), length(enable ) == 1L , ! is.na(enable ))
45+ options [[" progressr.enable" ]] <- enable
46+ }
47+ if (length(options ) > 0L ) {
48+ oopts <- options(options )
3949 on.exit(options(oopts ))
4050 }
4151
0 commit comments