|
22 | 22 | #' @param auto_finish (logical) If TRUE, then the progressor will signal a |
23 | 23 | #' [progression] 'finish' condition as soon as the last step has been reached. |
24 | 24 | #' |
| 25 | +#' @param enable (logical) If TRUE, [progression] conditions are signaled when |
| 26 | +#' calling the progressor function created by this function. |
| 27 | +#' If FALSE, no [progression] conditions is signaled because the progressor |
| 28 | +#' function is an empty function that does nothing. |
| 29 | +#' |
25 | 30 | #' @param on_exit,envir (logical) If TRUE, then the created progressor will |
26 | 31 | #' signal a [progression] 'finish' condition when the calling frame exits. |
27 | 32 | #' This is ignored if the calling frame (`envir`) is the global environment. |
|
31 | 36 | #' @export |
32 | 37 | progressor <- local({ |
33 | 38 | progressor_count <- 0L |
34 | | - |
35 | | - function(steps = length(along), along = NULL, offset = 0L, scale = 1L, transform = function(steps) scale * steps + offset, message = character(0L), label = NA_character_, initiate = TRUE, auto_finish = TRUE, on_exit = !identical(envir, globalenv()), envir = parent.frame()) { |
| 39 | + |
| 40 | + void_progressor <- function(...) NULL |
| 41 | + environment(void_progressor)$enable <- FALSE |
| 42 | + class(void_progressor) <- c("progressor", class(void_progressor)) |
| 43 | + |
| 44 | + function(steps = length(along), along = NULL, offset = 0L, scale = 1L, transform = function(steps) scale * steps + offset, message = character(0L), label = NA_character_, initiate = TRUE, auto_finish = TRUE, on_exit = !identical(envir, globalenv()), enable = getOption("progressr.enable", TRUE), envir = parent.frame()) { |
| 45 | + stop_if_not(is.logical(enable), length(enable) == 1L, !is.na(enable)) |
| 46 | + |
| 47 | + ## Quickly return a moot progressor function? |
| 48 | + if (!enable) return(void_progressor) |
| 49 | + |
36 | 50 | stop_if_not(!is.null(steps) || !is.null(along)) |
37 | 51 | stop_if_not(length(steps) == 1L, is.numeric(steps), !is.na(steps), |
38 | 52 | steps >= 0) |
@@ -123,6 +137,8 @@ print.progressor <- function(x, ...) { |
123 | 137 | s <- c(s, paste("- progression_index:", e$progression_index)) |
124 | 138 | owner_session_uuid <- e$owner_session_uuid |
125 | 139 | s <- c(s, paste("- owner_session_uuid:", owner_session_uuid)) |
| 140 | + |
| 141 | + s <- c(s, paste("- enable:", e$enable)) |
126 | 142 |
|
127 | 143 | s <- paste(s, collapse = "\n") |
128 | 144 | cat(s, "\n", sep = "") |
|
0 commit comments