Skip to content

Commit b7467ae

Browse files
slow_sum() now signals zero-amount progression conditions
1 parent e471bdd commit b7467ae

23 files changed

+93
-38
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.1.2-9000 [2019-06-26]
4+
Version: 0.1.2-9000 [2019-06-27]
55

66
NEW FEATURES:
77

@@ -11,6 +11,9 @@ NEW FEATURES:
1111

1212
* Add utility function handlers() for controlling option 'progressr.handlers'.
1313

14+
* Progression handlers' internal state now has a sticky 'message' field,
15+
which hold the most recent, non-empty progression 'message' received.
16+
1417

1518
Version: 0.1.2 [2019-06-14]
1619

R/options.R

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@
2828
#' \item{\option{progressr.intrusiveness}:}{(numeric) A non-negative scalar on how intrusive (disruptive) the reporter to the user. This multiplicative scalar applies to the _interval_ and _times_ parameters. (Default: `1.0`)\cr
2929
#'
3030
#' \describe{
31-
#' \item{\option{progressr.intrusiveness.auditory}:}{(numeric) intrusiveness for auditory progress handlers (Default: `10.0`)}
31+
#' \item{\option{progressr.intrusiveness.auditory}:}{(numeric) intrusiveness for auditory progress handlers (Default: `5.0`)}
3232
#' \item{\option{progressr.intrusiveness.file}:}{(numeric) intrusiveness for file-based progress handlers (Default: `5.0`)}
3333
#' \item{\option{progressr.intrusiveness.gui}:}{(numeric) intrusiveness for graphical-user-interface progress handlers (Default: `1.0`)}
3434
#' \item{\option{progressr.intrusiveness.notifier}:}{(numeric) intrusiveness for progress handlers that creates notifications (Default: `10.0`)}
@@ -57,7 +57,7 @@
5757
#' @section Options for progressr examples and demos:
5858
#'
5959
#' \describe{
60-
#' \item{\option{delay}:}{(numeric) Delay (in seconds) between each iteration of [slow_sum()]. (Default: `0.05`)}
60+
#' \item{\option{progressr.delay}:}{(numeric) Delay (in seconds) between each iteration of [slow_sum()]. (Default: `1.0`)}
6161
#' }
6262
#'
6363
#'

R/progression_handlers.R

Lines changed: 10 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -14,11 +14,11 @@
1414
#' @example incl/ascii_alert_handler.R
1515
#'
1616
#' @export
17-
ascii_alert_handler <- function(symbol = "\a", file = stderr(), intrusiveness = getOption("progressr.intrusiveness.auditory", 10), ...) {
17+
ascii_alert_handler <- function(symbol = "\a", file = stderr(), intrusiveness = getOption("progressr.intrusiveness.auditory", 5.0), ...) {
1818
reporter <- local({
1919
list(
2020
update = function(config, state, progression, ...) {
21-
if (state$enabled) cat(file = file, symbol)
21+
if (state$enabled && progression$amount != 0) cat(file = file, symbol)
2222
}
2323
)
2424
})
@@ -79,7 +79,7 @@ txtprogressbar_handler <- function(style = 3L, file = stderr(), intrusiveness =
7979
},
8080

8181
update = function(config, state, progression, ...) {
82-
if (!state$enabled || config$times == 1L) return()
82+
if (!state$enabled || progression$amount == 0 || config$times == 1L) return()
8383
make_pb(max = config$max_steps, style = style, file = file)
8484
setTxtProgressBar(pb, value = state$step)
8585
},
@@ -158,7 +158,7 @@ tkprogressbar_handler <- function(intrusiveness = getOption("progressr.intrusive
158158
},
159159

160160
update = function(config, state, progression, ...) {
161-
if (!state$enabled || config$times <= 2L) return()
161+
if (!state$enabled || progression$amount == 0 || config$times <= 2L) return()
162162
make_pb(max = config$max_steps, label = state$message)
163163
setTkProgressBar(pb, value = state$step, label = state$message)
164164
},
@@ -226,7 +226,7 @@ winprogressbar_handler <- function(intrusiveness = getOption("progressr.intrusiv
226226
},
227227

228228
update = function(config, state, progression, ...) {
229-
if (!state$enabled || config$times <= 2L) return()
229+
if (!state$enabled || progression$amount == 0 || config$times <= 2L) return()
230230
make_pb(max = config$max_steps, label = state$message)
231231
setWinProgressBar(pb, value = state$step, label = state$message)
232232
},
@@ -317,7 +317,7 @@ pbmcapply_handler <- function(substyle = 3L, style = "ETA", file = stderr(), int
317317
},
318318

319319
update = function(config, state, progression, ...) {
320-
if (!state$enabled || config$times <= 2L) return()
320+
if (!state$enabled || progression$amount == 0 || config$times <= 2L) return()
321321
make_pb(max = config$max_steps, style = style, substyle = substyle, file = file)
322322
setTxtProgressBar(pb, value = state$step)
323323
},
@@ -440,7 +440,7 @@ progress_handler <- function(format = "[:bar] :percent :message", show_after = 0
440440
#' @example incl/beepr_handler.R
441441
#'
442442
#' @export
443-
beepr_handler <- function(initiate = 2L, update = 10L, finish = 11L, intrusiveness = getOption("progressr.intrusiveness.auditory", 10), ...) {
443+
beepr_handler <- function(initiate = 2L, update = 10L, finish = 11L, intrusiveness = getOption("progressr.intrusiveness.auditory", 5.0), ...) {
444444
## Used for package testing purposes only when we want to perform
445445
## everything except the last part where the backend is called
446446
if (!is_fake("beepr_handler")) {
@@ -464,7 +464,7 @@ beepr_handler <- function(initiate = 2L, update = 10L, finish = 11L, intrusiven
464464
},
465465

466466
update = function(config, state, progression, ...) {
467-
if (!state$enabled || config$times <= 2L) return()
467+
if (!state$enabled || progression$amount == 0 || config$times <= 2L) return()
468468
beep(update)
469469
},
470470

@@ -520,7 +520,7 @@ notifier_handler <- function(intrusiveness = getOption("progressr.intrusiveness.
520520
},
521521

522522
update = function(config, state, progression, ...) {
523-
if (!state$enabled || config$times <= 2L) return()
523+
if (!state$enabled || progression$amount == 0 || config$times <= 2L) return()
524524
notify(step = state$step, max_steps = config$max_steps, message = state$message)
525525
},
526526

@@ -638,6 +638,7 @@ filesize_handler <- function(file = "default.progress", intrusiveness = getOptio
638638
current_size <- file.size(file)
639639
if (is.na(current_size)) file.create(file, showWarnings = FALSE)
640640
if (size == 0L) return()
641+
if (progression$amount == 0) return()
641642

642643
head <- sprintf("%g/%g: ", state$step, config$max_steps)
643644
nhead <- nchar(head)

R/slow_sum.R

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,17 +15,27 @@
1515
#' This function signals [progression] conditions as it progresses.
1616
#'
1717
#' @export
18-
slow_sum <- function(x, delay = getOption("delay", 0.05), stdout = FALSE, message = FALSE) {
18+
slow_sum <- function(x, delay = getOption("progressr.delay", 1.0), stdout = FALSE, message = TRUE) {
1919
progress <- progressor(length(x))
2020

2121
sum <- 0
2222
for (kk in seq_along(x)) {
23+
progress(amount = 0) ## "I'm alive" progression update
24+
Sys.sleep(0.2*delay)
2325
if (stdout) cat(sprintf("O: Element #%d\n", kk))
24-
Sys.sleep(delay)
26+
progress(amount = 0)
27+
Sys.sleep(0.2*delay)
28+
progress(amount = 0)
29+
Sys.sleep(0.2*delay)
2530
sum <- sum + x[kk]
2631
progress(message = sprintf("P: Adding %g", kk))
32+
Sys.sleep(0.2*delay)
2733
if (message) message(sprintf("M: Added value %g", x[kk]))
34+
progress(amount = 0)
35+
Sys.sleep(0.2*delay)
2836
}
2937

38+
progress(amount = 0)
39+
3040
sum
3141
}

R/utils.R

Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -111,3 +111,46 @@ known_progression_handlers <- function() {
111111
`%||%` <- function(lhs, rhs) {
112112
if (is.null(lhs)) rhs else lhs
113113
}
114+
115+
116+
## From R.utils 2.7.0 (2018-08-26)
117+
query_r_cmd_check <- function(...) {
118+
evidences <- list()
119+
120+
# Command line arguments
121+
args <- commandArgs()
122+
evidences[["vanilla"]] <- is.element("--vanilla", args)
123+
124+
# Check the working directory
125+
pwd <- getwd()
126+
dirname <- basename(pwd)
127+
parent <- basename(dirname(pwd))
128+
pattern <- ".+[.]Rcheck$"
129+
130+
# Is 'R CMD check' checking tests?
131+
evidences[["tests"]] <- (
132+
(regexpr(pattern, parent) != -1) &&
133+
(regexpr("^tests(|_.*)$", dirname) != -1)
134+
)
135+
136+
# Is the current working directory as expected?
137+
evidences[["pwd"]] <- (evidences[["tests"]] || (regexpr(pattern, dirname) != -1))
138+
139+
# Is 'R CMD check' checking examples?
140+
evidences[["examples"]] <- is.element("CheckExEnv", search())
141+
142+
143+
if (!evidences$vanilla || !evidences$pwd) {
144+
res <- "notRunning"
145+
} else if (evidences$tests) {
146+
res <- "checkingTests"
147+
} else if (evidences$examples) {
148+
res <- "checkingExamples"
149+
} else {
150+
res <- "notRunning"
151+
}
152+
153+
res
154+
}
155+
156+
in_r_cmd_check <- function() { query_r_cmd_check() != "notRunning" }

incl/progress_handler.R

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
if (requireNamespace("progress", quietly = TRUE)) {
2-
handlers("progress")
2+
handlers(progress_handler(format = ":spin [:bar] :percent :message"))
33
with_progress({ y <- slow_sum(1:10) })
44
print(y)
55
}

man/ascii_alert_handler.Rd

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

man/beepr_handler.Rd

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

man/progress_handler.Rd

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

man/progressr.options.Rd

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

0 commit comments

Comments
 (0)