Skip to content

Commit ea111ef

Browse files
with_progress() muffles a progression condition, if progressor is finished [#178]
1 parent 3b87f64 commit ea111ef

File tree

4 files changed

+32
-3
lines changed

4 files changed

+32
-3
lines changed

DESCRIPTION

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
Package: progressr
2-
Version: 0.16.0-9005
2+
Version: 0.16.0-9006
33
Title: An Inclusive, Unifying API for Progress Updates
44
Description: A minimal, unifying API for scripts and packages to report progress updates from anywhere including when using parallel processing. The package is designed such that the developer can to focus on what progress should be reported on without having to worry about how to present it. The end user has full control of how, where, and when to render these progress updates, e.g. in the terminal using utils::txtProgressBar(), cli::cli_progress_bar(), in a graphical user interface using utils::winProgressBar(), tcltk::tkProgressBar() or shiny::withProgress(), via the speakers using beepr::beep(), or on a file system via the size of a file. Anyone can add additional, customized, progression handlers. The 'progressr' package uses R's condition framework for signaling progress updated. Because of this, progress can be reported from almost anywhere in R, e.g. from classical for and while loops, from map-reduce API:s like the lapply() family of functions, 'purrr', 'plyr', and 'foreach'. It will also work with parallel processing via the 'future' framework, e.g. future.apply::future_lapply(), furrr::future_map(), and 'foreach' with 'doFuture'. The package is compatible with Shiny applications.
55
Authors@R: c(person("Henrik", "Bengtsson",

NEWS.md

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,19 @@
11
# Version (development version)
22

3+
## Significant Changes
4+
5+
* Now `with_progress()` muffles a `progression` condition, if the
6+
progressor becomes complete ("reaches 100%"). This prevents it from
7+
reaching, say, any global condition handlers and further attempts
8+
to complete the already completed progressor.
9+
310
## Bug Fixes
411

12+
* Using `with_progress()` together with `handlers(global = TRUE)`
13+
would produce a warning on "Received a progression 'update' request
14+
(...) but is not listening to this progressor". Above update to
15+
`with_progress()` avoids this warning.
16+
517
* Shiny apps running as background jobs in RStudio could fail with an
618
error "object 'RStudio.Version' of mode 'function' was not found".
719
This error occurred sporadically.

R/with_progress.R

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,11 @@
4444
#' If the global progression handler is enabled, it is temporarily disabled
4545
#' while evaluating the `expr` expression.
4646
#'
47+
#' If a `progression` condition causes the progressor to be completed
48+
#' ("reaches 100%"), then `with_progress()` will muffle the `progression`
49+
#' condition preventing it from reaching, say, any global condition
50+
#' handlers.
51+
#'
4752
#' **IMPORTANT: This function is meant for end users only. It should not
4853
#' be used by R packages, which only task is to _signal_ progress updates,
4954
#' not to decide if, when, and how progress should be reported.**
@@ -240,9 +245,16 @@ with_progress <- function(expr, handlers = progressr::handlers(), cleanup = TRUE
240245
}
241246

242247
## Let the registered 'progressr' calling handlers process
243-
## the 'progression' condition. If the progressor completed,
244-
## then 'finished' is TRUE (which we currently don't use)
248+
## the 'progression' condition. If this resulted in the
249+
## progressor being completed, then 'finished' is TRUE
245250
finished <- calling_handler(p)
251+
252+
## If the progressor is completed, muffle the 'progression'
253+
## condition already here, to prevent it from reaching other
254+
## handlers such as global 'progression' handlers.
255+
if (finished) {
256+
invokeRestart("muffleProgression")
257+
}
246258
},
247259

248260
interrupt = handle_interrupt_or_error,

man/with_progress.Rd

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

0 commit comments

Comments
 (0)