Skip to content

Commit 25f2d37

Browse files
handlers() gained argument 'append'
1 parent a44bb01 commit 25f2d37

File tree

5 files changed

+22
-10
lines changed

5 files changed

+22
-10
lines changed

NEWS

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,14 @@
11
Package: progressr
22
==================
33

4-
Version: 0.2.1-9000 [2020-01-12]
4+
Version: 0.2.1-9000 [2020-01-20]
55

66
NEW FEATURES:
77

88
* progressor() gained offset and slope arguments 'a' and 'b', and functional
99
argument 'transform'.
10+
11+
* handlers() gained argument 'append' to make it easier to append handlers.
1012

1113
BUG FIXES:
1214

R/handlers.R

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,9 @@
55
#' If this vector is empty, then an empty set of progression handlers will
66
#' be set.
77
#'
8+
#' @param append (logial) If FALSE, the specified progression handlers replace
9+
#' the current ones, otherwise appended to them.
10+
#'
811
#' @param on_missing (character) If `"error"`, an error is thrown if one of
912
#' the progression handlers does not exists. If `"warning"`, a warning
1013
#' is produces and the missing handlers is ignored. If `"ignore"`, the
@@ -24,7 +27,7 @@
2427
#' @example incl/handlers.R
2528
#'
2629
#' @export
27-
handlers <- function(..., on_missing = c("error", "warning", "ignore"), default = txtprogressbar_handler) {
30+
handlers <- function(..., append = FALSE, on_missing = c("error", "warning", "ignore"), default = txtprogressbar_handler) {
2831
args <- list(...)
2932

3033
## Get the current set of progression handlers?
@@ -82,5 +85,10 @@ handlers <- function(..., on_missing = c("error", "warning", "ignore"), default
8285
keep <- vapply(handlers, FUN = is.function, FUN.VALUE = FALSE)
8386
handlers <- handlers[keep]
8487

88+
if (append) {
89+
current <- getOption("progressr.handlers", list())
90+
if (length(current) > 0L) handlers <- c(current, handlers)
91+
}
92+
8593
options(progressr.handlers = handlers)[[1]]
8694
}

incl/with_progress.R

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -40,14 +40,13 @@ if (requireNamespace("beepr", quietly = TRUE)) {
4040

4141
## Progress reported via customied utils::txtProgressBar, beepr::beep,
4242
## and notifier::notify, if available.
43-
handlers <- list(txtprogressbar_handler(style = 3L))
43+
handlers(txtprogressbar_handler(style = 3L))
4444
if (requireNamespace("beepr", quietly = TRUE)) {
45-
handlers <- c(handlers, list(beepr_handler()))
45+
handlers("beepr", append = TRUE)
4646
}
4747
if (requireNamespace("notifier", quietly = TRUE)) {
48-
handlers <- c(handlers, list(notifier_handler(times = 3L, interval = 0.1)))
48+
handlers(notifier_handler(times = 3L, interval = 0.1), append = TRUE)
4949
}
50-
handlers(handlers)
5150

5251
with_progress({
5352
y <- slow_sum(1:30)

man/handlers.Rd

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

man/with_progress.Rd

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

0 commit comments

Comments
 (0)