Skip to content

Commit 01857cb

Browse files
committed
Restore test 1775.1 for print() options
Instead, test substitute(x) for %iscall% "print" to decide whether to print the x before testing the output.
1 parent b0f41d5 commit 01857cb

File tree

2 files changed

+11
-7
lines changed

2 files changed

+11
-7
lines changed

R/test.data.table.R

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -487,7 +487,11 @@ test = function(num,x,y=TRUE,error=NULL,warning=NULL,message=NULL,output=NULL,no
487487
# save the overhead of capture.output() since there are a lot of tests, often called in loops
488488
# Thanks to tryCatch2 by Jan here : https://github.com/jangorecki/logR/blob/master/R/logR.R#L21
489489
} else {
490-
out = capture.output(print(x <- suppressMessages(withCallingHandlers(tryCatch(x, error=eHandler), warning=wHandler, message=mHandler))))
490+
out = if (xsub %iscall% "print") {
491+
capture.output(x <- suppressMessages(withCallingHandlers(tryCatch(x, error=eHandler), warning=wHandler, message=mHandler)))
492+
} else {
493+
capture.output(print(x <- suppressMessages(withCallingHandlers(tryCatch(x, error=eHandler), warning=wHandler, message=mHandler))))
494+
}
491495
}
492496
if (!is.null(options)) {
493497
# some of the options passed to test() may break internal data.table use below (e.g. invalid datatable.alloccol), so undo them ASAP

inst/tests/tests.Rraw

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -11887,7 +11887,7 @@ test(1774.17, as.data.table(x, na.rm='a'), error="'na.rm' must be scalar")
1188711887

1188811888
# verify print.keys works
1188911889
DT1 <- data.table(a = 1:3, key = "a")
11890-
test(1775.1, DT1, options = c(datatable.print.keys = TRUE),
11890+
test(1775.1, print(DT1, print.keys = TRUE),
1189111891
output = c("Key: <a>", " a", "1: 1", "2: 2", "3: 3"))
1189211892
DT2 <- data.table(a = 1:3, b = 4:6)
1189311893
setindexv(DT2, c("b","a"))
@@ -16704,10 +16704,10 @@ test(2125.05, print(DT, trunc.cols=TRUE, class=TRUE, row.names=FALSE),
1670416704
"1 variable not shown: \\[d <char>\\]"))
1670516705
test(2125.06, print(DT, trunc.cols=TRUE, col.names="none"),
1670616706
output=c("^ 1: 0 bbbbbbbbbbbbb ccccccccccccc", ".*",
16707-
"1 variable not shown: \\[d\\]", ""))
16707+
"1 variable not shown: \\[d\\]$"))
1670816708
test(2125.07, print(DT, trunc.cols=TRUE, class=TRUE, col.names="none"),
1670916709
output=c("^ 1: 0 bbbbbbbbbbbbb", ".*",
16710-
"2 variables not shown: \\[c, d\\]", ""),
16710+
"2 variables not shown: \\[c, d\\]$"),
1671116711
warning = "Column classes will be suppressed when col.names is 'none'")
1671216712
options("width" = 20)
1671316713
DT = data.table(a = vector("integer", 2),
@@ -21490,11 +21490,11 @@ test(2328.2, droplevels(DT), data.table(f=factor(), i=integer(), f2=factor()))
2149021490

2149121491
#6882 print() output with col.names="none"
2149221492
dt = data.table(short = 1:3, verylongcolumnname = 4:6)
21493-
test(2329.1, print(dt, col.names = "none"), output = "1: 1 4\n2: 2 5\n3: 3 6\n")
21493+
test(2329.1, print(dt, col.names = "none"), output = "1: 1 4\n2: 2 5\n3: 3 6$")
2149421494
dt = data.table(x = 123456, y = "wide_string")
21495-
test(2329.2, print(dt, col.names = "none"), output = "1: 123456 wide_string\n")
21495+
test(2329.2, print(dt, col.names = "none"), output = "1: 123456 wide_string$")
2149621496
dt = data.table(a = NA_integer_, b = NaN)
21497-
test(2329.3, print(dt, col.names = "none"), output = "1: NA NaN\n")
21497+
test(2329.3, print(dt, col.names = "none"), output = "1: NA NaN$")
2149821498

2149921499
# Row name extraction from multiple vectors, #7136
2150021500
x <- 1:3

0 commit comments

Comments
 (0)