@@ -2031,17 +2031,19 @@ options(datatable.optimize = 2L)
20312031test(658.1, DT[ , mean(x), by=grp1, verbose=TRUE], output="GForce optimized j to.*gmean")
20322032test(658.2, DT[ , list(mean(x)), by=grp1, verbose=TRUE], output="GForce optimized j to.*gmean")
20332033test(658.3, DT[ , list(mean(x), mean(y)), by=grp1, verbose=TRUE], output="GForce optimized j to.*gmean")
2034- tt = capture.output(DT[,list(mean(x),mean(y)),by=list(grp1,grp2),verbose=TRUE])
2035- test(659, !length(grep("Wrote less rows", tt))) # first group is one row with this seed. Ensure we treat this as aggregate case rather than allocate too many rows.
2034+ # first group is one row with this seed. Ensure we treat this as aggregate case rather than allocate too many rows.
2035+ test(659, DT[,list(mean(x),mean(y)),by=list(grp1,grp2),verbose=TRUE], notOutput = "Wrote less rows")
20362036
20372037# Test .N for logical i subset
20382038DT = data.table(a=1:10, b=rnorm(10))
20392039test(660, DT[a==8L, .N], 1L)
20402040
20412041# Test that growing is sensible in worst case
20422042DT = data.table(a=rep(1:10,1:10),b=rnorm(55))
2043- tt = capture.output(DT[,sum(b)*b,by=a,verbose=TRUE])
2044- test(661, length(grep("growing from",tt))<3) # was 6 when we simply grew enough for latest result
2043+ test(661, DT[,sum(b)*b,by=a,verbose=TRUE],
2044+ notOutput = paste(rep("growing from", 3), collapse = ".*"))
2045+ # Need to test that "growing from" is printed less than three times.
2046+ # The number was previously 6 when we simply grew enough for latest result
20452047
20462048# Test that adding a new logical column is supported, #2094
20472049DT=data.table(a=1:3)
@@ -8286,8 +8288,8 @@ test(1579.03, dt[, lapply(.SD, median), keyby=x],
82868288 dt[, lapply(.SD, function(x) median(as.numeric(x))), keyby=x])
82878289test(1579.04, dt[, lapply(.SD, median, na.rm=TRUE), keyby=x],
82888290 dt[, lapply(.SD, function(x) median(as.numeric(x), na.rm=TRUE)), keyby=x])
8289- ans = capture.output( dt[, lapply(.SD, median), by=x, verbose=TRUE])
8290- test(1579.05, any(grepl( "GForce optimized", ans)), TRUE )
8291+ test(1579.05, dt[, lapply(.SD, median), by=x, verbose=TRUE],
8292+ output = "GForce optimized")
82918293
82928294# testing gforce::ghead and gforce::gtail
82938295# head(.SD, 1) and tail(.SD, 1) optimisation
@@ -8539,8 +8541,8 @@ if (x1==x2) {
85398541 # NB: x1==x2 is a condition in base R, independent of data.table
85408542 test(1590.12, forderv( c(x2,x1,x1,x2)), integer())
85418543 # don't test base ... test(1590.13, base::order(c(x2,x1,x1,x2)), 1:4)
8542- } else {
8543- # Windows-1252 , #2856
8544+ } else if (identical(l10n_info()$codepage, 1252L)) {
8545+ # US English ANSI codepage on Windows is CP1252 , #2856
85448546 test(1590.14, forderv( c(x2,x1,x1,x2)), INT(1,4,2,3))
85458547 # don't test base ... test(1590.15, base::order(c(x2,x1,x1,x2)), INT(1,4,2,3))
85468548}
@@ -9280,11 +9282,9 @@ test(1633.4, dt[, .SD, by=1:nrow(dt)], data.table(nrow=1:nrow(dt), dt)) # make s
92809282
92819283# reuse secondary indices
92829284dt = data.table(x=sample(3, 10, TRUE), y=1:10)
9283- v1 = capture.output(ans1 <- dt[.(3:2), on="x", verbose=TRUE])
9285+ test(1634.1, dt[.(3:2), on="x", verbose=TRUE], output = "ad hoc" )
92849286setindex(dt, x)
9285- v2 = capture.output(ans2 <- dt[.(3:2), on="x", verbose=TRUE])
9286- test(1634.1, any(grepl("ad hoc", v1)), TRUE)
9287- test(1634.2, any(grepl("existing index", v2)), TRUE)
9287+ test(1634.2, dt[.(3:2), on="x", verbose=TRUE], output = "existing index")
92889288
92899289# fread's fill argument detects separator better in complex cases as well, #1573
92909290# if pasted to the console, these tests won't work. But do work when sourced as these are tabs not spaces in text
@@ -10248,33 +10248,33 @@ options("datatable.use.index"=TRUE, "datatable.auto.index"=TRUE)
1024810248test(1666.01, d[k==1L, verbose=TRUE], d[3L], output="Creating new index 'k'")
1024910249d = data.table(k=3:1)
1025010250options("datatable.use.index"=TRUE, "datatable.auto.index"=FALSE)
10251- test(1666.02, grep("Creating new index", capture.output( d[k==1L, verbose=TRUE])), integer(0) ) # do not create index
10251+ test(1666.02, d[k==1L, verbose=TRUE], notOutput="Creating new index" ) # do not create index
1025210252d = data.table(k=3:1)
1025310253options("datatable.use.index"=FALSE, "datatable.auto.index"=FALSE)
10254- test(1666.03, grep("Creating new index", capture.output( d[k==1L, verbose=TRUE])), integer(0) )
10254+ test(1666.03, d[k==1L, verbose=TRUE], notOutput="Creating new index" )
1025510255d = data.table(k=3:1)
1025610256options("datatable.use.index"=FALSE, "datatable.auto.index"=TRUE)
10257- test(1666.04, grep("Creating new index", capture.output( d[k==1L, verbose=TRUE])), integer(0) )
10257+ test(1666.04, d[k==1L, verbose=TRUE], notOutput="Creating new index" )
1025810258d = data.table(k=3:1) # subset - index
1025910259setindex(d, k)
1026010260options("datatable.use.index"=TRUE, "datatable.auto.index"=TRUE)
1026110261test(1666.05, d[k==1L, verbose=TRUE], d[3L], output="Optimized subsetting with index 'k'")
1026210262options("datatable.use.index"=TRUE, "datatable.auto.index"=FALSE)
1026310263test(1666.06, d[k==1L, verbose=TRUE], d[3L], output="Optimized subsetting with index 'k'")
1026410264options("datatable.use.index"=FALSE, "datatable.auto.index"=FALSE)
10265- test(1666.07, grep("Using existing index", capture.output( d[k==1L, verbose=TRUE])), integer(0) ) # not using existing index
10265+ test(1666.07, d[k==1L, verbose=TRUE], notOutput="Using existing index" ) # not using existing index
1026610266options("datatable.use.index"=FALSE, "datatable.auto.index"=TRUE)
10267- test(1666.08, grep("Using existing index", capture.output( d[k==1L, verbose=TRUE])), integer(0) )
10267+ test(1666.08, d[k==1L, verbose=TRUE], notOutput="Using existing index" )
1026810268d1 = data.table(k=3:1) # join - no index
1026910269d2 = data.table(k=2:4)
1027010270options("datatable.use.index"=TRUE, "datatable.auto.index"=TRUE)
1027110271test(1666.09, d1[d2, on="k", verbose=TRUE], d1[d2, on="k"], output="ad hoc")
1027210272options("datatable.use.index"=TRUE, "datatable.auto.index"=FALSE)
1027310273test(1666.10, d1[d2, on="k", verbose=TRUE], d1[d2, on="k"], output="ad hoc")
1027410274options("datatable.use.index"=FALSE, "datatable.auto.index"=FALSE)
10275- test(1666.11, grep("Looking for existing (secondary) index", capture.output( d1[d2, on="k", verbose=TRUE])), integer(0) ) # not looking for index
10275+ test(1666.11, d1[d2, on="k", verbose=TRUE], notOutput="Looking for existing (secondary) index" ) # not looking for index
1027610276options("datatable.use.index"=FALSE, "datatable.auto.index"=TRUE)
10277- test(1666.12, grep("Looking for existing (secondary) index", capture.output( d1[d2, on="k", verbose=TRUE])), integer(0) )
10277+ test(1666.12, d1[d2, on="k", verbose=TRUE], notOutput="Looking for existing (secondary) index" )
1027810278d1 = data.table(k=3:1,v1=10:12) # join - index
1027910279d2 = data.table(k=2:4,v2=20:22)
1028010280setindex(d1, k)
@@ -11653,8 +11653,7 @@ test(1765.4, {warning("foobar1"); warning("foobar2"); warning("FOO"); 4L}, 4L, i
1165311653test(1765.5, {warning("foobar1"); warning("foobar2"); warning("FOO"); 4L}, 4L, ignore.warning="2", warning=c("foobar1","FOO"))
1165411654
1165511655# print(null.data.table()) should not output NULL as well, #1852
11656- # use capture.output() in this case rather than output= to ensure NULL is not output
11657- test(1766, capture.output(print(data.table(NULL))), "Null data.table (0 rows and 0 cols)")
11656+ test(1766, data.table(NULL), notOutput = "NULL$")
1165811657
1165911658# Bug on subset of 1-row data.table when expr returns a named logical vector #2152
1166011659options(datatable.auto.index=FALSE)
@@ -11888,8 +11887,8 @@ test(1774.17, as.data.table(x, na.rm='a'), error="'na.rm' must be scalar")
1188811887
1188911888# verify print.keys works
1189011889DT1 <- data.table(a = 1:3, key = "a")
11891- test(1775.1, capture.output( print(DT1, print.keys = TRUE) ),
11892- c("Key: <a>", " a", "1: 1", "2: 2", "3: 3"))
11890+ test(1775.1, print(DT1, print.keys = TRUE),
11891+ output = c("Key: <a>", " a", "1: 1", "2: 2", "3: 3"))
1189311892DT2 <- data.table(a = 1:3, b = 4:6)
1189411893setindexv(DT2, c("b","a"))
1189511894test(1775.2, print(DT2, print.keys = TRUE),
@@ -13675,7 +13674,7 @@ test(1962.034, setkeyv(DT, c('a', '')),
1367513674setkey(DT, a)
1367613675test(1962.035, {setkeyv(DT, character(0L)); key(DT)}, NULL,
1367713676 warning = 'cols is a character vector of zero length')
13678- test(1962.036, any(grepl('already ordered', capture.output( setkey(DT, a, verbose = TRUE)))) )
13677+ test(1962.036, setkey(DT, a, verbose = TRUE), output = 'already ordered' )
1367913678setnames(DT, '.xi')
1368013679setkey(DT, NULL)
1368113680test(1962.037, setkey(DT, .xi),
@@ -16321,7 +16320,7 @@ test(2094.02, X$TAG, rep(names(x), each = 2))
1632116320
1632216321# use arbitrary column without message when fun.aggregate=length, #2980
1632316322DT = data.table(a=c(3L, 3L, 2L, 9L, 5L, 10L, 3L, 2L, 9L, 8L), b=rep(1:5, 2))
16324- test(2095, any(grepl('override', capture.output( dcast(DT, a~b, fun.aggregate=length)), fixed=TRUE)), FALSE )
16323+ test(2095, dcast(DT, a~b, fun.aggregate=length), notOutput='override' )
1632516324
1632616325# gmean intermediate can overflow integers without warning, #986
1632716326test(2096, data.table(a=c(1L,1L), v=c(2e9L, 2e9L))[, mean(v), a], data.table(a=1L, V1=2e9))
@@ -16705,10 +16704,10 @@ test(2125.05, print(DT, trunc.cols=TRUE, class=TRUE, row.names=FALSE),
1670516704 "1 variable not shown: \\[d <char>\\]"))
1670616705test(2125.06, print(DT, trunc.cols=TRUE, col.names="none"),
1670716706 output=c("^ 1: 0 bbbbbbbbbbbbb ccccccccccccc", ".*",
16708- "1 variable not shown: \\[d\\]", " "))
16707+ "1 variable not shown: \\[d\\]$ "))
1670916708test(2125.07, print(DT, trunc.cols=TRUE, class=TRUE, col.names="none"),
1671016709 output=c("^ 1: 0 bbbbbbbbbbbbb", ".*",
16711- "2 variables not shown: \\[c, d\\]", " "),
16710+ "2 variables not shown: \\[c, d\\]$ "),
1671216711 warning = "Column classes will be suppressed when col.names is 'none'")
1671316712options("width" = 20)
1671416713DT = data.table(a = vector("integer", 2),
@@ -21491,11 +21490,11 @@ test(2328.2, droplevels(DT), data.table(f=factor(), i=integer(), f2=factor()))
2149121490
2149221491#6882 print() output with col.names="none"
2149321492dt = data.table(short = 1:3, verylongcolumnname = 4:6)
21494- 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$ ")
2149521494dt = data.table(x = 123456, y = "wide_string")
21496- 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$ ")
2149721496dt = data.table(a = NA_integer_, b = NaN)
21498- 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$ ")
2149921498
2150021499# Row name extraction from multiple vectors, #7136
2150121500x <- 1:3
0 commit comments