Skip to content

Commit 60b87f4

Browse files
Merge branch 'release/0.1.3'
2 parents e93974a + 551f49d commit 60b87f4

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

66 files changed

+2124
-281
lines changed

.Rbuildignore

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -58,3 +58,5 @@ Rplots.pdf$
5858
^.ghi
5959
^.issues
6060
^last.dump*
61+
62+
vignettes/

DESCRIPTION

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,15 @@
11
Package: progressr
2-
Version: 0.1.2
2+
Version: 0.1.3
33
Title: A Unifying API for Progress Updates
44
Description: A minimal API for reporting progress updates upstream. The design is to separate the representation of progress updates from how they are presented. What type of progress to signal is controlled by the developer. How these progress updates are rendered is controlled by the end user. For instance, some users may prefer visual feedback such as a horizontal progress bar in the terminal, whereas others may prefer auditory feedback.
55
Authors@R: c(
66
person("Henrik", "Bengtsson", role=c("aut", "cre", "cph"),
77
email = "[email protected]"))
88
License: GPL (>= 3)
99
Imports:
10-
digest
10+
digest,
11+
utils
1112
Suggests:
12-
utils,
1313
tcltk,
1414
beepr,
1515
notifier,

NAMESPACE

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,8 @@ export(ascii_alert_handler)
77
export(beepr_handler)
88
export(debug_handler)
99
export(filesize_handler)
10+
export(handlers)
11+
export(make_progression_handler)
1012
export(newline_handler)
1113
export(notifier_handler)
1214
export(pbmcapply_handler)
@@ -15,7 +17,6 @@ export(progress_aggregator)
1517
export(progress_handler)
1618
export(progress_progressr)
1719
export(progression)
18-
export(progression_handler)
1920
export(progressor)
2021
export(slow_sum)
2122
export(tkprogressbar_handler)
@@ -27,4 +28,6 @@ importFrom(digest,digest)
2728
importFrom(utils,capture.output)
2829
importFrom(utils,file_test)
2930
importFrom(utils,flush.console)
31+
importFrom(utils,setTxtProgressBar)
3032
importFrom(utils,str)
33+
importFrom(utils,txtProgressBar)

NEWS

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,20 @@
11
Package: progressr
22
==================
33

4+
Version: 0.1.3 [2019-07-01]
5+
6+
NEW FEATURES:
7+
8+
* Now it is possible to send "I'm still here" progression updates by setting
9+
the progress step to zero, e.g. progress(amount = 0). This type of
10+
information can for instance be used to updated a progress bar spinner.
11+
12+
* Add utility function handlers() for controlling option 'progressr.handlers'.
13+
14+
* Progression handlers' internal state now has a sticky 'message' field,
15+
which hold the most recent, non-empty progression 'message' received.
16+
17+
418
Version: 0.1.2 [2019-06-14]
519

620
NEW FEATURES:

OVERVIEW.md

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -102,6 +102,19 @@ with_progress({
102102
```
103103

104104

105+
## Roadmap
106+
107+
Because this project is under active development, the progressr API is currently kept at a very minimum. This will allow for the framework and the API to evolve while minimizing the risk for breaking code that depends on it. The roadmap for developing the API is roughly:
108+
109+
1. Provide minimal API for producing progress updates, i.e. `progressor()` and `with_progress()`
110+
111+
2. Add support for nested progress updates
112+
113+
3. Add API to allow users and package developers to design additional progression handlers
114+
115+
For a more up-to-date view on what features might be added, see <https://github.com/HenrikBengtsson/progressr/issues>.
116+
117+
105118
## Appendix
106119

107120
### Debugging

R/handlers.R

Lines changed: 80 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,80 @@
1+
#' Get and Set the List of Progression Handlers
2+
#'
3+
#' @param \dots One or more progression handlers. Alternatively, this
4+
#' functions accepts also a single vector of progression handlers as input.
5+
#' If this vector is empty, then an empty set of progression handlers will
6+
#' be set.
7+
#'
8+
#' @param on_missing (character) If `"error"`, an error is thrown if one of
9+
#' the progression handlers does not exists. If `"warning"`, a warning
10+
#' is produces and the missing handlers is ignored. If `"ignore"`, the
11+
#' missing handlers is ignored.
12+
#'
13+
#' @return (invisibly) the previous list of progression handlers set.
14+
#' If no arguments are specified, then the current set of progression
15+
#' handlers is returned.
16+
#'
17+
#' @details
18+
#' This function provides a convenient alternative for getting and setting
19+
#' option \option{progressr.handlers}.
20+
#'
21+
#' @example incl/handlers.R
22+
#'
23+
#' @export
24+
handlers <- function(..., on_missing = c("error", "warning", "ignore")) {
25+
args <- list(...)
26+
27+
## Get the current set of progression handlers?
28+
if (length(args) == 0L) return(getOption("progressr.handlers"))
29+
30+
on_missing <- match.arg(on_missing)
31+
32+
## Was a list specified?
33+
if (length(args) == 1L && is.vector(args[[1]])) {
34+
args <- args[[1]]
35+
}
36+
37+
handlers <- list()
38+
names <- names(args)
39+
for (kk in seq_along(args)) {
40+
handler <- args[[kk]]
41+
stop_if_not(length(handler) == 1L)
42+
43+
if (is.character(handler)) {
44+
name <- handler
45+
name2 <- sprintf("%s_handler", name)
46+
47+
handler <- NULL
48+
if (exists(name2, mode = "function")) {
49+
handler <- get(name2, mode = "function")
50+
}
51+
52+
if (is.null(handler)) {
53+
if (exists(name, mode = "function")) {
54+
handler <- get(name, mode = "function")
55+
}
56+
}
57+
58+
if (is.null(handler)) {
59+
if (on_missing == "error") {
60+
stop("No such progression handler found: ", sQuote(name))
61+
} else if (on_missing == "warning") {
62+
warning("Ignoring non-existing progression handler: ", sQuote(name))
63+
}
64+
next
65+
}
66+
67+
names[kk] <- name
68+
}
69+
stop_if_not(is.function(handler), length(formals(handler)) >= 1L)
70+
handlers[[kk]] <- handler
71+
}
72+
stop_if_not(is.list(handlers))
73+
names(handlers) <- names
74+
75+
## Drop non-existing handlers
76+
keep <- vapply(handlers, FUN = is.function, FUN.VALUE = FALSE)
77+
handlers <- handlers[keep]
78+
79+
options(progressr.handlers = handlers)[[1]]
80+
}

R/options.R

Lines changed: 74 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,74 @@
1+
#' Options used for progressr
2+
#'
3+
#' Below are all \R options that are currently used by the \pkg{progressr} package.\cr
4+
#' \cr
5+
#' \emph{WARNING: Note that the names and the default values of these options may change in future versions of the package. Please use with care until further notice.}
6+
#'
7+
#'
8+
#' @section Options for controlling progression reporting:
9+
#'
10+
#' \describe{
11+
#' \item{\option{progressr.handlers}:}{(function or list of functions) Zero or more progression handlers that will report on any progression updates. If NULL or an empty list, progress updates are ignored. (Default: `txtprogressbar_handler`)}
12+
#' }
13+
#'
14+
#'
15+
#' @section Options for controlling progression handlers:
16+
#'
17+
#' \describe{
18+
#' \item{\option{progressr.clear}:}{(logical) If TRUE, any output, typically visual, produced by a reporter will be cleared/removed upon completion, if possible. (Default: TRUE)}
19+
#'
20+
#' \item{\option{progressr.enable}:}{(logical) If FALSE, then progress is not reported. (Default: TRUE)}
21+
#'
22+
#' \item{\option{progressr.enable_after}:}{(numeric) Delay (in seconds) before progression updates are reported. (Default: `0.0`)}
23+
#'
24+
#' \item{\option{progressr.times}:}{(numeric) The maximum number of times a handler should report progression updates. If zero, then progress is not reported. (Default: `+Inf`)}
25+
#'
26+
#' \item{\option{progressr.interval}:}{(numeric) The minimum time (in seconds) between successive progression updates from this handler. (Default: `0.0`)}
27+
#'
28+
#' \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
29+
#'
30+
#' \describe{
31+
#' \item{\option{progressr.intrusiveness.auditory}:}{(numeric) intrusiveness for auditory progress handlers (Default: `5.0`)}
32+
#' \item{\option{progressr.intrusiveness.file}:}{(numeric) intrusiveness for file-based progress handlers (Default: `5.0`)}
33+
#' \item{\option{progressr.intrusiveness.gui}:}{(numeric) intrusiveness for graphical-user-interface progress handlers (Default: `1.0`)}
34+
#' \item{\option{progressr.intrusiveness.notifier}:}{(numeric) intrusiveness for progress handlers that creates notifications (Default: `10.0`)}
35+
#' \item{\option{progressr.intrusiveness.terminal}:}{(numeric) intrusiveness for progress handlers that outputs to the terminal (Default: `1.0`)}
36+
#' \item{\option{progressr.intrusiveness.debug}:}{(numeric) intrusiveness for "debug" progress handlers (Default: `0.0`)}
37+
#' }
38+
#' }
39+
#' }
40+
#'
41+
#' @section Options for controlling how standard output and conditions are relayed:
42+
#'
43+
#' \describe{
44+
#' \item{\option{progressr.delay_conditions}:}{(character vector) condition classes to be captured and relayed at the end after any captured standard output is relayed. (Default: `c("condition")`)}
45+
#'
46+
#' \item{\option{progressr.delay_stdout}:}{(logical) If TRUE, standard output is captured and relayed at the end just before any captured conditions are relayed. (Default: TRUE)}
47+
#' }
48+
#'
49+
#'
50+
#' @section Options for debugging progression updates:
51+
#'
52+
#' \describe{
53+
#' \item{\option{progressr.debug}:}{(logical) If TRUE, extensive debug messages are generated. (Default: FALSE)}
54+
#' }
55+
#'
56+
#'
57+
#' @section Options for progressr examples and demos:
58+
#'
59+
#' \describe{
60+
#' \item{\option{progressr.delay}:}{(numeric) Delay (in seconds) between each iteration of [slow_sum()]. (Default: `1.0`)}
61+
#' }
62+
#'
63+
#'
64+
#' @seealso
65+
#' 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 configurating \R's startup process.
66+
#'
67+
#' @aliases
68+
#' progressr.debug
69+
#' progressr.handlers
70+
#' progressr.clear
71+
#'
72+
#' @keywords internal
73+
#' @name progressr.options
74+
NULL

R/progress_aggregator.R

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ progress_aggregator <- function(progress) {
3939
invokeRestart("muffleProgression")
4040
}
4141

42-
handler <- progression_handler("progress_aggregator", handler = handler)
42+
handler <- make_progression_handler("progress_aggregator", handler = handler)
4343

4444
fcn <- function(...) {
4545
with_progress(..., handlers = handler)

R/progression.R

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,11 @@
11
#' A Progression Condition
22
#'
3-
#' @param amount (numeric) The total amount of progress made.
3+
#' A progression condition represents a progress in an \R program.
44
#'
55
#' @param message (character) A progress message.
66
#'
7+
#' @param amount (numeric) The total amount of progress made.
8+
#'
79
#' @param step (character or integer) The step completed.
810
#'
911
#' @param time (POSIXct) A timestamp.
@@ -35,7 +37,7 @@
3537
#' To create and signal a progression condition at once, use [progress()].
3638
#'
3739
#' @export
38-
progression <- function(amount = 1.0, message = character(0L), step = NULL, time = progression_time, ..., type = "update", class = NULL, progressor_uuid = NULL, progression_index = NULL, progression_time = Sys.time(), call = NULL, owner_session_uuid = NULL) {
40+
progression <- function(message = character(0L), amount = 1.0, step = NULL, time = progression_time, ..., type = "update", class = NULL, progressor_uuid = NULL, progression_index = NULL, progression_time = Sys.time(), call = NULL, owner_session_uuid = NULL) {
3941
message <- as.character(message)
4042
amount <- as.numeric(amount)
4143
time <- as.POSIXct(time)
@@ -78,8 +80,8 @@ progression <- function(amount = 1.0, message = character(0L), step = NULL, time
7880
print.progression <- function(x, ...) {
7981
s <- sprintf("%s:", class(x)[1])
8082
s <- c(s, paste("- call:", deparse(conditionCall(x))))
81-
s <- c(s, paste("- message:", sQuote(conditionMessage(x))))
8283
s <- c(s, paste("- type:", x$type))
84+
s <- c(s, paste("- message:", sQuote(conditionMessage(x))))
8385
s <- c(s, paste("- amount:", x$amount))
8486
s <- c(s, paste("- step:", x$step))
8587
s <- c(s, paste("- time:", x$time))

0 commit comments

Comments
 (0)