Skip to content

Commit 15c32ff

Browse files
R_PROGRESSR_* environment variables are now only read when the 'progressr' package is loaded
1 parent 8120da9 commit 15c32ff

File tree

7 files changed

+56
-19
lines changed

7 files changed

+56
-19
lines changed

NEWS

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,14 @@ SIGNIFICANT CHANGES:
88
* Creating a new progressor() will now automatically finish an existing
99
progressor in the same environment. The previous behavior was to give an
1010
error (see below bug fix).
11+
12+
* R_PROGRESSR_* environment variables are now only read when the 'progressr'
13+
package is loaded, where they set the corresponding progressr.* option.
14+
Previously, some of these environment variables were queried by different
15+
functions as a fallback to when an option was not set. By only parsing
16+
them when the package is loaded, it decrease the overhead in functions,
17+
and it clarifies that options can be changed at runtime whereas environment
18+
variables should only be set at startup.
1119

1220
NEW FEATURES:
1321

R/make_progression_handler.R

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,7 @@
5050
#'
5151
#' @keywords internal
5252
#' @export
53-
make_progression_handler <- function(name, reporter = list(), handler = NULL, enable = getOption("progressr.enable", Sys.getenv("R_PROGRESSR_ENABLE", interactive())), enable_after = getOption("progressr.enable_after", Sys.getenv("R_PROGRESSR_ENABLE_AFTER", 0.0)), times = getOption("progressr.times", Sys.getenv("R_PROGRESSR_TIMES", +Inf)), interval = getOption("progressr.interval", Sys.getenv("R_PROGRESSR_INTERVAL", 0.0)), intrusiveness = 1.0, clear = getOption("progressr.clear", Sys.getenv("R_PROGRESSR_CLEAR", TRUE)), target = "terminal", ...) {
53+
make_progression_handler <- function(name, reporter = list(), handler = NULL, enable = getOption("progressr.enable", interactive()), enable_after = getOption("progressr.enable_after", 0.0), times = getOption("progressr.times", +Inf), interval = getOption("progressr.interval", 0.0), intrusiveness = 1.0, clear = getOption("progressr.clear", TRUE), target = "terminal", ...) {
5454
enable <- as.logical(enable)
5555
stop_if_not(is.logical(enable), length(enable) == 1L, !is.na(enable))
5656
if (!enable) times <- 0

R/options.R

Lines changed: 23 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -21,30 +21,30 @@
2121
#' @section Options for controlling progression handlers:
2222
#'
2323
#' \describe{
24-
#' \item{\option{progressr.clear} / \env{R_PROGRESSR_CLEAR}:}{
24+
#' \item{\option{progressr.clear}:}{
2525
#' (logical)
2626
#' If TRUE, any output, typically visual, produced by a reporter will be cleared/removed upon completion, if possible. (Default: TRUE)
2727
#' }
2828
#'
29-
#' \item{\option{progressr.enable} / \env{R_PROGRESSR_ENABLE}:}{
29+
#' \item{\option{progressr.enable}:}{
3030
#' (logical)
3131
#' If FALSE, then progress is not reported.
3232
#' (Default: TRUE)
3333
#' }
3434
#'
35-
#' \item{\option{progressr.enable_after} / \env{R_PROGRESSR_ENABLE_AFTER}:}{
35+
#' \item{\option{progressr.enable_after}:}{
3636
#' (numeric)
3737
#' Delay (in seconds) before progression updates are reported.
3838
#' (Default: `0.0`)
3939
#' }
4040
#'
41-
#' \item{\option{progressr.times} / \env{R_PROGRESSR_TIMES}:}{
41+
#' \item{\option{progressr.times}:}{
4242
#' (numeric)
4343
#' The maximum number of times a handler should report progression updates. If zero, then progress is not reported.
4444
#' (Default: `+Inf`)
4545
#' }
4646
#'
47-
#' \item{\option{progressr.interval} / \env{R_PROGRESSR_INTERVAL}:}{
47+
#' \item{\option{progressr.interval}:}{
4848
#' (numeric)
4949
#' The minimum time (in seconds) between successive progression updates from this handler.
5050
#' (Default: `0.0`)
@@ -93,6 +93,14 @@
9393
#' \item{\option{progressr.demo.delay}:}{(numeric) Delay (in seconds) between each iteration of [slow_sum()]. (Default: `1.0`)}
9494
#' }
9595
#'
96+
#' @section Environment variables that set R options:
97+
#' Some of the above \R \option{progressr.*} options can be set by corresponding
98+
#' environment variable \env{R_PROGRESSR_*} _when the \pkg{progressr} package
99+
#' is loaded_.
100+
#' For example, if `R_PROGRESSR_ENABLE = "true"`, then option
101+
#' \option{progressr.enable} is set to `TRUE` (logical).
102+
#' For example, if `R_PROGRESSR_ENABLE_AFTER = "2.0"`, then option
103+
#' \option{progressr.enable_after} is set to `2.0` (numeric).
96104
#'
97105
#' @seealso
98106
#' To set \R options when \R starts (even before the \pkg{progressr} package is loaded), see the \link[base]{Startup} help page. The \href{https://cran.r-project.org/package=startup}{\pkg{startup}} package provides a friendly mechanism for configuring \R at startup.
@@ -218,6 +226,16 @@ update_package_option <- function(name, mode = "character", default = NULL, pack
218226
update_package_options <- function(debug = FALSE) {
219227
update_package_option("demo.delay", mode = "numeric", debug = debug)
220228

229+
## make_progression_handler() arguments
230+
update_package_option("clear", mode = "logical", default = TRUE, debug = debug)
231+
update_package_option("enable", mode = "logical", default = interactive(), debug = debug)
232+
update_package_option("enable_after", mode = "numeric", default = 0.0, debug = debug)
233+
update_package_option("interval", mode = "numeric", default = 0.0, debug = debug)
234+
update_package_option("times", mode = "numeric", default = +Inf, debug = debug)
235+
236+
## Life-cycle, e.g. deprecation an defunct
237+
update_package_option("lifecycle.progress", mode = "character", default = "deprecated", debug = debug)
238+
221239
## However, not used
222240
update_package_option("global.handler", mode = "logical", debug = debug)
223241
}

R/progress.R

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@
1515
#' @keywords internal
1616
#' @export
1717
progress <- function(..., call = sys.call()) {
18-
action <- getOption("progressr.progress", "deprecated")
18+
action <- getOption("progressr.lifecycle.progress", "deprecated")
1919
signal <- switch(action, deprecated = .Deprecated, defunct = .Defunct)
2020
signal(msg = sprintf("progress() is %s", action), package = .packageName)
2121

R/utils.R

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -73,6 +73,8 @@ comma <- function(x, sep = ", ") paste(x, collapse = sep)
7373

7474
commaq <- function(x, sep = ", ") paste(sQuote(x), collapse = sep)
7575

76+
trim <- function(s) sub("[\t\n\f\r ]+$", "", sub("^[\t\n\f\r ]+", "", s))
77+
7678
stop_if_not <- function(..., calls = sys.calls()) {
7779
res <- list(...)
7880
n <- length(res)

man/make_progression_handler.Rd

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

man/progressr.options.Rd

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

0 commit comments

Comments
 (0)