Skip to content

Commit f34cd12

Browse files
Added print() for 'progression_handler' objects.
1 parent 4fcb4c2 commit f34cd12

File tree

4 files changed

+75
-2
lines changed

4 files changed

+75
-2
lines changed

NAMESPACE

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
# Generated by roxygen2: do not edit by hand
22

33
S3method(print,progression)
4+
S3method(print,progression_handler)
45
S3method(print,progressor)
56
export(ascii_alert_handler)
67
export(beepr_handler)

NEWS

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,8 @@ NEW FEATURES:
99
to setting corresponding options progressr.*.
1010

1111
* Now option 'progressr.interval' defaults to 0.0 (was 0.5 seconds).
12+
13+
* Added print() for 'progression_handler' objects.
1214

1315

1416
Version: 0.1.1 [2019-06-08]

R/progression_handler.R

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -279,3 +279,35 @@ progression_handler <- function(name, reporter = list(), handler = NULL, enable
279279

280280
handler
281281
}
282+
283+
284+
#' @export
285+
print.progression_handler <- function(x, ...) {
286+
print(sys.calls())
287+
s <- sprintf("Progression handler of class %s:", sQuote(class(x)[1]))
288+
289+
env <- environment(x)
290+
s <- c(s, " * configuration:")
291+
s <- c(s, sprintf(" - name: %s", sQuote(env$name %||% "<NULL>")))
292+
s <- c(s, sprintf(" - max_steps: %s", env$max_steps %||% "<NULL>"))
293+
s <- c(s, sprintf(" - enable: %g", env$enable))
294+
s <- c(s, sprintf(" - enable_after: %g seconds", env$enable_after))
295+
s <- c(s, sprintf(" - times: %g", env$times))
296+
s <- c(s, sprintf(" - interval: %g seconds", env$interval))
297+
s <- c(s, sprintf(" - intrusiveness: %g", env$intrusiveness))
298+
s <- c(s, sprintf(" - auto_finish: %s", env$auto_finish))
299+
s <- c(s, sprintf(" - clear: %s", env$clear))
300+
s <- c(s, sprintf(" - milestones: %s", hpaste(env$milestones %||% "<NULL>")))
301+
s <- c(s, sprintf(" - owner: %s", hpaste(env$owner %||% "<NULL>")))
302+
303+
s <- c(s, " * state:")
304+
s <- c(s, sprintf(" - enabled: %s", env$enabled))
305+
s <- c(s, sprintf(" - finished: %s", env$finished))
306+
s <- c(s, sprintf(" - step: %s", env$step %||% "<NULL>"))
307+
s <- c(s, sprintf(" - prev_milestone: %s", env$prev_milestone %||% "<NULL>"))
308+
s <- c(s, sprintf(" - delta: %g", (env$step - env$prev_milestone) %||% 0L))
309+
s <- c(s, sprintf(" - timestamps: %s", hpaste(env$timestamps %||% "<NULL>")))
310+
311+
s <- paste(s, collapse = "\n")
312+
cat(s, "\n", sep = "")
313+
}

R/utils.R

Lines changed: 40 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,35 @@
1+
## From R.utils 2.0.2 (2015-05-23)
2+
hpaste <- function(..., sep = "", collapse = ", ", lastCollapse = NULL, maxHead = if (missing(lastCollapse)) 3 else Inf, maxTail = if (is.finite(maxHead)) 1 else Inf, abbreviate = "...") {
3+
if (is.null(lastCollapse)) lastCollapse <- collapse
4+
5+
# Build vector 'x'
6+
x <- paste(..., sep = sep)
7+
n <- length(x)
8+
9+
# Nothing todo?
10+
if (n == 0) return(x)
11+
if (is.null(collapse)) return(x)
12+
13+
# Abbreviate?
14+
if (n > maxHead + maxTail + 1) {
15+
head <- x[seq_len(maxHead)]
16+
tail <- rev(rev(x)[seq_len(maxTail)])
17+
x <- c(head, abbreviate, tail)
18+
n <- length(x)
19+
}
20+
21+
if (!is.null(collapse) && n > 1) {
22+
if (lastCollapse == collapse) {
23+
x <- paste(x, collapse = collapse)
24+
} else {
25+
xT <- paste(x[1:(n-1)], collapse = collapse)
26+
x <- paste(xT, x[n], sep = lastCollapse)
27+
}
28+
}
29+
30+
x
31+
} # hpaste()
32+
133
# More efficient than the default utils::capture.output()
234
#' @importFrom utils capture.output
335
capture_output <- function(expr, envir = parent.frame(), ...) {
@@ -70,6 +102,12 @@ is_fake <- local({
70102
known_progression_handlers <- function() {
71103
ns <- asNamespace(.packageName)
72104
handlers <- ls(envir = ns, pattern = "_handler$")
73-
handlers <- setdiff(handlers, "progression_handler")
74-
mget(handlers, envir = ns, inherits = FALSE)
105+
handlers <- setdiff(handlers, c("progression_handler", "print.progression_handler"))
106+
handlers <- mget(handlers, envir = ns, inherits = FALSE)
107+
handlers
108+
}
109+
110+
111+
`%||%` <- function(lhs, rhs) {
112+
if (is.null(lhs)) rhs else lhs
75113
}

0 commit comments

Comments
 (0)