Skip to content

Commit e039a49

Browse files
handlers() did not return a list if the 'default' handler was returned
1 parent 5cc1024 commit e039a49

File tree

6 files changed

+88
-2
lines changed

6 files changed

+88
-2
lines changed

NEWS

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,8 @@ Version: 0.2.0-9000 [2020-01-04]
66
BUG FIXES:
77

88
* winprogressbar_handler() would produce error "invalid 'Label' argument".
9+
10+
* handlers() did not return a list if the 'default' handler was returned.
911

1012

1113
Version: 0.2.0 [2020-01-04]

OVERVIEW.md

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -310,4 +310,3 @@ To debug progress updates, use:
310310
[doFuture]: https://cran.r-project.org/package=doFuture
311311
[foreach]: https://cran.r-project.org/package=foreach
312312
[furrr]: https://cran.r-project.org/package=furrr
313-

R/handlers.R

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,10 @@ handlers <- function(..., on_missing = c("error", "warning", "ignore"), default
2828
args <- list(...)
2929

3030
## Get the current set of progression handlers?
31-
if (length(args) == 0L) return(getOption("progressr.handlers", default))
31+
if (length(args) == 0L) {
32+
if (!is.list(default)) default <- list(default)
33+
return(getOption("progressr.handlers", default))
34+
}
3235

3336
on_missing <- match.arg(on_missing)
3437

tests/handlers.R

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
source("incl/start.R")
2+
3+
message("handlers() ...")
4+
5+
hs <- handlers()
6+
print(hs)
7+
8+
hs <- handlers("txtprogressbar")
9+
print(hs)
10+
print(hs[[1]])
11+
12+
message("handlers() ... DONE")
13+
14+
source("incl/end.R")

tests/incl/start,load-only.R

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,11 +7,15 @@ oopts0 <- options()
77
oopts <- options()
88

99
## Private
10+
`%||%` <- progressr:::`%||%`
11+
hpaste <- progressr:::hpaste
1012
mdebug <- progressr:::mdebug
1113
mprint <- progressr:::mprint
1214
mprintf <- progressr:::mprintf
1315
mstr <- progressr:::mstr
16+
in_r_cmd_check <- progressr:::in_r_cmd_check
1417
stop_if_not <- progressr:::stop_if_not
18+
printf <- function(...) cat(sprintf(...))
1519
known_progression_handlers <- progressr:::known_progression_handlers
1620

1721
non_supported_progression_handlers <- function() {

tests/utils.R

Lines changed: 64 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,54 @@ source("incl/start.R")
33
message("*** utils ...")
44

55

6+
message("*** hpaste() ...")
7+
8+
# Some vectors
9+
x <- 1:6
10+
y <- 10:1
11+
z <- LETTERS[x]
12+
13+
# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
14+
# Abbreviation of output vector
15+
# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
16+
printf("x = %s.\n", hpaste(x))
17+
## x = 1, 2, 3, ..., 6.
18+
19+
printf("x = %s.\n", hpaste(x, maxHead = 2))
20+
## x = 1, 2, ..., 6.
21+
22+
printf("x = %s.\n", hpaste(x), maxHead = 3) # Default
23+
## x = 1, 2, 3, ..., 6.
24+
25+
# It will never output 1, 2, 3, 4, ..., 6
26+
printf("x = %s.\n", hpaste(x, maxHead = 4))
27+
## x = 1, 2, 3, 4, 5 and 6.
28+
29+
# Showing the tail
30+
printf("x = %s.\n", hpaste(x, maxHead = 1, maxTail = 2))
31+
## x = 1, ..., 5, 6.
32+
33+
# Turning off abbreviation
34+
printf("y = %s.\n", hpaste(y, maxHead = Inf))
35+
## y = 10, 9, 8, 7, 6, 5, 4, 3, 2, 1
36+
37+
## ...or simply
38+
printf("y = %s.\n", paste(y, collapse = ", "))
39+
## y = 10, 9, 8, 7, 6, 5, 4, 3, 2, 1
40+
41+
# Change last separator
42+
printf("x = %s.\n", hpaste(x, lastCollapse = " and "))
43+
## x = 1, 2, 3, 4, 5 and 6.
44+
45+
# No collapse
46+
stopifnot(all(hpaste(x, collapse = NULL) == x))
47+
48+
# Empty input
49+
stopifnot(identical(hpaste(character(0)), character(0)))
50+
51+
message("*** hpaste() ... DONE")
52+
53+
654
message("*** mdebug() ...")
755

856
mdebug("Hello #", 1)
@@ -32,6 +80,22 @@ tryCatch(stop_if_not(c(1,2,3,4,5,6,7,8,9,10,1,2,3,4,5,6,7,8,9,10,1,2,3,4,5,6,7,8
3280

3381
message("*** stop_if_not() ... done")
3482

83+
84+
message("*** %||% ...")
85+
86+
print(NULL %||% TRUE)
87+
88+
print(TRUE %||% FALSE)
89+
90+
message("*** %||% ... done")
91+
92+
message("*** in_r_cmd_check() ...")
93+
94+
print(in_r_cmd_check())
95+
96+
message("*** in_r_cmd_check() ... done")
97+
98+
3599
message("*** utils ... DONE")
36100

37101
source("incl/end.R")

0 commit comments

Comments
 (0)