Skip to content

Commit

Permalink
BUG FIX: withProgressShiny() could produce an 'if (config$max_steps =…
Browse files Browse the repository at this point in the history
…= 0) : ... argument is of length zero' error [#165]
  • Loading branch information
HenrikBengtsson committed Oct 19, 2024
1 parent b8efbd9 commit 832ce4e
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 1 deletion.
2 changes: 1 addition & 1 deletion DESCRIPTION
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
Package: progressr
Version: 0.14.0-9005
Version: 0.14.0-9006
Title: An Inclusive, Unifying API for Progress Updates
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.
Authors@R: c(person("Henrik", "Bengtsson",
Expand Down
3 changes: 3 additions & 0 deletions NEWS.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,9 @@

## Bug Fixes

* `withProgressShiny()` could produce an `if (config$max_steps ==
0) : ... argument is of length zero` error.

* `handlers(new_handlers)` would return `NULL`, instead of `list()`,
if there were no prior handlers set.

Expand Down
12 changes: 12 additions & 0 deletions R/handler_shiny.R
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,12 @@ handler_shiny <- function(intrusiveness = getOption("progressr.intrusiveness.gui
reporter <- local({
list(
interrupt = function(config, state, progression, ...) {
if (!state$enabled) return()
stop_if_not(
length(config$max_steps) == 1L, is.numeric(config$max_steps),
!is.na(config$max_steps), is.finite(config$max_steps),
config$max_steps >= 0
)
msg <- conditionMessage(progression)
amount <- if (config$max_steps == 0) 1 else progression$amount / config$max_steps
args <- c(
Expand All @@ -64,6 +70,12 @@ handler_shiny <- function(intrusiveness = getOption("progressr.intrusiveness.gui
},

update = function(config, state, progression, ...) {
if (!state$enabled) return()
stop_if_not(
length(config$max_steps) == 1L, is.numeric(config$max_steps),
!is.na(config$max_steps), is.finite(config$max_steps),
config$max_steps >= 0
)
amount <- if (config$max_steps == 0) 1 else progression$amount / config$max_steps
args <- c(
list(amount = amount),
Expand Down

0 comments on commit 832ce4e

Please sign in to comment.