Skip to content

Commit b989b36

Browse files
with_progress() gained argument 'interval'
1 parent 1e8c28d commit b989b36

File tree

3 files changed

+23
-8
lines changed

3 files changed

+23
-8
lines changed

NEWS

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,11 @@
11
Package: progressr
22
==================
33

4-
Version: 0.1.1-9000 [2019-06-08]
4+
Version: 0.1.1-9000 [2019-06-13]
55

6-
* ...
6+
NEW FEATURES:
7+
8+
* with_progress() gained argument 'interval'.
79

810

911
Version: 0.1.1 [2019-06-08]

R/with_progress.R

Lines changed: 14 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -15,20 +15,30 @@
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?

man/with_progress.Rd

Lines changed: 5 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)