Skip to content

Commit f8ca1ec

Browse files
with_progress() gained argument 'enable' [#53]
1 parent b989b36 commit f8ca1ec

File tree

3 files changed

+18
-4
lines changed

3 files changed

+18
-4
lines changed

NEWS

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,8 @@ Version: 0.1.1-9000 [2019-06-13]
55

66
NEW FEATURES:
77

8-
* with_progress() gained argument 'interval'.
8+
* with_progress() gained arguments 'enable' and 'interval' as an alternative
9+
to setting corresponding options progressr.*.
910

1011

1112
Version: 0.1.1 [2019-06-08]

R/with_progress.R

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,12 +18,14 @@
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

man/with_progress.Rd

Lines changed: 4 additions & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)