Skip to content

Commit a896610

Browse files
Now supporting zero-length progressors (fixes #108)
1 parent c18d395 commit a896610

File tree

6 files changed

+18
-10
lines changed

6 files changed

+18
-10
lines changed

NEWS

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

4-
Version: 0.7.0-9000 [2021-02-28]
4+
Version: 0.7.0-9000 [2021-04-25]
55

66
SIGNIFICANT CHANGES:
77

@@ -11,6 +11,9 @@ SIGNIFICANT CHANGES:
1111

1212
NEW FEATURES:
1313

14+
* Now supporting zero-length progressors, e.g. p <- progressor(along = x)
15+
where length(x) == 0.
16+
1417
* Add handlers("rstudio") to report on progress in the RStudio Console via
1518
the RStudio Job interface.
1619

R/handler_filesize.R

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@
2727
handler_filesize <- function(file = "default.progress", intrusiveness = getOption("progressr.intrusiveness.file", 5), target = "file", ...) {
2828
reporter <- local({
2929
set_file_size <- function(config, state, progression) {
30-
ratio <- state$step / config$max_steps
30+
ratio <- if (config$max_steps == 0) 1 else state$step / config$max_steps
3131
size <- round(100 * ratio)
3232
current_size <- file.size(file)
3333
if (is.na(current_size)) file.create(file, showWarnings = FALSE)

R/handler_notifier.R

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,8 @@ handler_notifier <- function(intrusiveness = getOption("progressr.intrusiveness.
2929
}
3030

3131
notify <- function(step, max_steps, message) {
32-
ratio <- sprintf("%.0f%%", 100*step/max_steps)
32+
ratio <- if (max_steps == 0) 1 else step / max_steps
33+
ratio <- sprintf("%.0f%%", 100*ratio)
3334
msg <- paste(c("", message), collapse = "")
3435
notifier_notify(sprintf("[%s] %s", ratio, msg))
3536
}

R/handler_pbcol.R

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,8 @@ handler_pbcol <- function(adjust = 0.0, pad = 1L, complete = function(s) crayon:
6161
list(
6262
initiate = function(config, state, ...) {
6363
if (!state$enabled || config$times <= 2L) return()
64-
redraw_progress_bar(ratio = state$step / config$max_steps, message = state$message, spin = spinner[spin_state+1L])
64+
ratio <- if (config$max_steps == 0) 1 else state$step / config$max_steps
65+
redraw_progress_bar(ratio = ratio, message = state$message, spin = spinner[spin_state+1L])
6566
},
6667

6768
reset = function(...) {
@@ -74,14 +75,16 @@ handler_pbcol <- function(adjust = 0.0, pad = 1L, complete = function(s) crayon:
7475

7576
unhide = function(config, state, ...) {
7677
if (!state$enabled || config$times <= 2L) return()
77-
redraw_progress_bar(ratio = state$step / config$max_steps, message = state$message, spin = spinner[spin_state+1L])
78+
ratio <- if (config$max_steps == 0) 1 else state$step / config$max_steps
79+
redraw_progress_bar(ratio = ratio, message = state$message, spin = spinner[spin_state+1L])
7880
},
7981

8082
update = function(config, state, progression, ...) {
8183
if (!state$enabled || config$times <= 2L) return()
8284
if (state$delta < 0) return()
8385
spin_state <<- (spin_state+1L) %% length(spinner)
84-
redraw_progress_bar(ratio = state$step / config$max_steps, message = state$message, spin = spinner[spin_state+1L])
86+
ratio <- if (config$max_steps == 0) 1 else state$step / config$max_steps
87+
redraw_progress_bar(ratio = ratio, message = state$message, spin = spinner[spin_state+1L])
8588
},
8689

8790
finish = function(...) {

R/handler_shiny.R

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -25,8 +25,8 @@ handler_shiny <- function(intrusiveness = getOption("progressr.intrusiveness.gui
2525
reporter <- local({
2626
list(
2727
update = function(config, state, progression, ...) {
28-
shiny::incProgress(amount = progression$amount / config$max_steps,
29-
message = state$message)
28+
amount <- if (config$max_steps == 0) 1 else progression$amount / config$max_steps
29+
shiny::incProgress(amount = amount, message = state$message)
3030
}
3131
)
3232
})

R/make_progression_handler.R

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -349,15 +349,16 @@ make_progression_handler <- function(name, reporter = list(), handler = NULL, en
349349
}
350350
max_steps <<- p[["steps"]]
351351
if (debug) mstr(list(max_steps=max_steps))
352-
stop_if_not(!is.null(max_steps), is.numeric(max_steps), length(max_steps) == 1L, max_steps >= 1)
352+
stop_if_not(!is.null(max_steps), is.numeric(max_steps), length(max_steps) == 1L, max_steps >= 0)
353353
auto_finish <<- p[["auto_finish"]]
354354
times <- min(times, max_steps)
355355
if (debug) mstr(list(auto_finish = auto_finish, times = times, interval = interval, intrusiveness = intrusiveness))
356356

357357
## Adjust 'times' and 'interval' according to 'intrusiveness'
358-
times <- min(times / intrusiveness, max_steps)
358+
times <- min(c(times / intrusiveness, max_steps), na.rm = TRUE)
359359
times <- max(times, 1L)
360360
interval <- interval * intrusiveness
361+
if (debug) mstr(list(times = times, interval = interval))
361362

362363
## Milestone steps that need to be reach in order to trigger an
363364
## update of the reporter

0 commit comments

Comments
 (0)