Skip to content

Commit f507222

Browse files
Add support for progressor(along = ...)
1 parent 67b8b18 commit f507222

File tree

7 files changed

+20
-8
lines changed

7 files changed

+20
-8
lines changed

.Rbuildignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -60,3 +60,4 @@ Rplots.pdf$
6060
^last.dump*
6161

6262
vignettes/
63+
^*.gif$

NEWS

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

4-
Version: 0.1.3-9000 [2019-07-01]
4+
Version: 0.1.3-9000 [2019-07-02]
55

6-
* ...
6+
NEW FEATURES:
7+
8+
* Add support for progressor(along = ...).
79

810

911
Version: 0.1.3 [2019-07-01]

R/progressor.R

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,8 @@
22
#'
33
#' @param steps (integer) Maximum number of steps.
44
#'
5+
#' @param along (vector; alternative) Corresponds to `steps = seq_along(along)`.
6+
#'
57
#' @param label (character) A label.
68
#'
79
#' @param initiate (logical) If TRUE, the progressor will signal a
@@ -16,7 +18,12 @@
1618
progressor <- local({
1719
progressor_count <- 0L
1820

19-
function(steps, label = NA_character_, initiate = TRUE, auto_finish = TRUE) {
21+
function(steps = NULL, along = NULL, label = NA_character_, initiate = TRUE, auto_finish = TRUE) {
22+
stop_if_not(!is.null(steps) || !is.null(along))
23+
if (!is.null(along)) steps <- length(along)
24+
stop_if_not(length(steps) == 1L, is.numeric(steps), !is.na(steps),
25+
steps >= 0)
26+
2027
label <- as.character(label)
2128
stop_if_not(length(label) == 1L)
2229

R/slow_sum.R

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@
1616
#'
1717
#' @export
1818
slow_sum <- function(x, delay = getOption("progressr.delay", 1.0), stdout = FALSE, message = TRUE) {
19-
progress <- progressor(length(x))
19+
progress <- progressor(along = x)
2020

2121
sum <- 0
2222
for (kk in seq_along(x)) {

man/progressor.Rd

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

tests/progress_handler.R

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ x <- 1:10
1515
message("progress_handler() ...")
1616

1717
with_progress({
18-
progress <- progressor(length(x))
18+
progress <- progressor(along = x)
1919
for (ii in x) {
2020
Sys.sleep(delay)
2121
progress(message = sprintf("(%s)", paste(letters[1:ii], collapse="")))

tests/tkprogressbar_handler.R

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ x <- 1:10
1414

1515
message("progress_handler() ...")
1616
with_progress({
17-
progress <- progressor(length(x))
17+
progress <- progressor(along = x)
1818
for (ii in x) {
1919
Sys.sleep(delay)
2020
progress(message = sprintf("(%s)", paste(letters[1:ii], collapse="")))

0 commit comments

Comments
 (0)