From 1b5c5932ff3c69719fc7454da94cb9483b7edb6c Mon Sep 17 00:00:00 2001 From: Anmol Sriwastava Date: Sat, 17 Oct 2026 00:01:17 +0530 Subject: [PATCH 1/8] Resolved off by one bug in print.trunc.cols(#7716) --- R/print.data.table.R | 4 ++-- inst/tests/tests.Rraw | 3 +++ 2 files changed, 5 insertions(+), 2 deletions(-) diff --git a/R/print.data.table.R b/R/print.data.table.R index f82a12cbab..b5d16fb656 100644 --- a/R/print.data.table.R +++ b/R/print.data.table.R @@ -91,7 +91,7 @@ print.data.table = function(x, topn=getOption("datatable.print.topn"), trunc.char = getOption("datatable.prettyprint.char") if (is.null(trunc.char)) { rn_w = if (isTRUE(row.names)) nchar(as.character(max(rn))) + 2L else 0L - trunc.char = max(0L, getOption("width") - rn_w - 3L) + trunc.char = max(0L, getOption("width") - rn_w) } toprint=format.data.table(toprint, na.encode=FALSE, timezone = timezone, trunc.char = trunc.char, ...) # na.encode=FALSE so that NA in character cols print as @@ -119,7 +119,7 @@ print.data.table = function(x, topn=getOption("datatable.print.topn"), # allow truncation of columns to print only what will fit in console PR #4074 widths = dt_width(toprint, n_x, class, row.names, col.names) cons_width = getOption("width") - cols_to_print = widths < cons_width + cols_to_print = widths <= cons_width not_printed = colnames(toprint)[!cols_to_print] if (!any(cols_to_print)) { trunc_cols_message(not_printed, abbs, class, col.names) diff --git a/inst/tests/tests.Rraw b/inst/tests/tests.Rraw index 78123b73fe..55d67a1009 100644 --- a/inst/tests/tests.Rraw +++ b/inst/tests/tests.Rraw @@ -22011,3 +22011,6 @@ test(2388.21, nafill(c(1, NA, NA, 5), type="nocb", limit=1, nan=NaN), c(1, NA, 5 test(2388.22, nafill(c(1L, NA, NA, 5L), type="nocb", limit=1), c(1L, NA, 5L, 5L)) test(2388.23, nafill(c("a", NA, NA), type="const", fill="x", limit=1), c("a", "x", NA)) test(2388.24, nafill(c("a", NA, NA, "z"), type="nocb", limit=1), c("a", NA, "z", "z")) + +# print.data.table truncates a table exactly matching console width, #7716 +test(2388.25, print(data.table(x="1234567")), output=" x\n \n1: 1234567", options=list(width=10, datatable.print.trunc.cols=TRUE)) \ No newline at end of file From 6f42bf3406bcb2b65097b2e957333c3e90d30784 Mon Sep 17 00:00:00 2001 From: Anmol Sriwastava Date: Sat, 17 Oct 2026 14:28:27 +0530 Subject: [PATCH 2/8] fix: print columns if first column is too long #7717 --- R/print.data.table.R | 20 ++++++++++++++++---- inst/tests/tests.Rraw | 5 ++++- 2 files changed, 20 insertions(+), 5 deletions(-) diff --git a/R/print.data.table.R b/R/print.data.table.R index b5d16fb656..dfba03f251 100644 --- a/R/print.data.table.R +++ b/R/print.data.table.R @@ -116,17 +116,29 @@ print.data.table = function(x, topn=getOption("datatable.print.topn"), } if (quote) colnames(toprint) <- paste0('"', old <- colnames(toprint), '"') if (isTRUE(trunc.cols)) { - # allow truncation of columns to print only what will fit in console PR #4074 - widths = dt_width(toprint, n_x, class, row.names, col.names) cons_width = getOption("width") + widths = dt_width(toprint, n_x, class, row.names, col.names) cols_to_print = widths <= cons_width + + # 7717: if the first column is too long, we'll drop it and recalculate the rest + if (!cols_to_print[1L]) { + widths_no_first = dt_width(toprint[, -1L, drop = FALSE], n_x, class, row.names, col.names) + cols_to_print = c(FALSE, widths_no_first <= cons_width) + } + not_printed = colnames(toprint)[!cols_to_print] + + # Print front msg if first column was dropped + if (!cols_to_print[1L]) { + trunc_cols_message(not_printed[1L], abbs, class, col.names) + not_printed = not_printed[-1L] + } + if (!any(cols_to_print)) { trunc_cols_message(not_printed, abbs, class, col.names) return(invisible(x)) } - # When nrow(toprint) = 1, attributes get lost in the subset, - # function below adds those back when necessary + toprint = toprint_subset(toprint, cols_to_print) trunc.cols = length(not_printed) > 0L } diff --git a/inst/tests/tests.Rraw b/inst/tests/tests.Rraw index 55d67a1009..dc6564d077 100644 --- a/inst/tests/tests.Rraw +++ b/inst/tests/tests.Rraw @@ -22013,4 +22013,7 @@ test(2388.23, nafill(c("a", NA, NA), type="const", fill="x", limit=1), c("a", "x test(2388.24, nafill(c("a", NA, NA, "z"), type="nocb", limit=1), c("a", NA, "z", "z")) # print.data.table truncates a table exactly matching console width, #7716 -test(2388.25, print(data.table(x="1234567")), output=" x\n \n1: 1234567", options=list(width=10, datatable.print.trunc.cols=TRUE)) \ No newline at end of file +test(2388.25, print(data.table(x="1234567")), output=" x\n \n1: 1234567", options=list(width=10, datatable.print.trunc.cols=TRUE)) + +# print.trunc.cols shows nothing if first column is too long #7717 +test(2388.26, print(data.table(x="123456789012", y=1, z=2, a=3)), output="1 variable not shown: [x ]\n y\n \n1: 1\n2 variables not shown: [z , a ]", options=list(width=10, datatable.print.trunc.cols=TRUE)) \ No newline at end of file From 39364b1f7992f4e04935f91be5bf12c5e33e7821 Mon Sep 17 00:00:00 2001 From: Anmol Sriwastava Date: Sun, 18 Oct 2026 10:42:28 +0530 Subject: [PATCH 3/8] fix: update old tests --- inst/tests/tests.Rraw | 25 ++++++++----------------- 1 file changed, 8 insertions(+), 17 deletions(-) diff --git a/inst/tests/tests.Rraw b/inst/tests/tests.Rraw index dc6564d077..cff8332df3 100644 --- a/inst/tests/tests.Rraw +++ b/inst/tests/tests.Rraw @@ -16350,7 +16350,7 @@ test(2125.03, print(DT, trunc.cols=TRUE, row.names=FALSE), # _exactly_ 40, but still wraps. If we set options(width=41) it won't truncate. # seems to be an issue with print.default. test(2125.04, print(DT, trunc.cols=TRUE, class=TRUE), - output="2 variables not shown: [c , d ]") + output="1 variable not shown: [a ]\n a b c\n \n 1: 0 bbbbbbbbbbbbb ccccccccccccc\n 2: 0 bbbbbbbbbbbbb ccccccccccccc\n 3: 0 bbbbbbbbbbbbb ccccccccccccc\n 4: 0 bbbbbbbbbbbbb ccccccccccccc\n 5: 0 bbbbbbbbbbbbb ccccccccccccc\n --- \n 98: 0 bbbbbbbbbbbbb ccccccccccccc\n 99: 0 bbbbbbbbbbbbb ccccccccccccc\n100: 0 bbbbbbbbbbbbb ccccccccccccc\n101: 0 bbbbbbbbbbbbb ccccccccccccc\n102: 0 bbbbbbbbbbbbb ccccccccccccc\n1 variable not shown: [d ]") test(2125.05, print(DT, trunc.cols=TRUE, class=TRUE, row.names=FALSE), output=c("^ a b c", ".*", "1 variable not shown: \\[d \\]")) @@ -16358,14 +16358,9 @@ test(2125.06, print(DT, trunc.cols=TRUE, col.names="none"), output=c("^ 1: 0 bbbbbbbbbbbbb ccccccccccccc", ".*", "1 variable not shown: \\[d\\]$")) test(2125.07, print(DT, trunc.cols=TRUE, class=TRUE, col.names="none"), - output=c("^ 1: 0 bbbbbbbbbbbbb", ".*", - "2 variables not shown: \\[c, d\\]$"), + output=c("^ 1: 0 bbbbbbbbbbbbb ccccccccccccc", ".*", + "1 variable not shown: \\[d\\]$"), warning = "Column classes will be suppressed when col.names is 'none'") -options("width" = 20) -DT = data.table(a = vector("integer", 2), - b = "bbbbbbbbbbbbb", - c = "ccccccccccccc", - d = "ddddddddddddd") test(2125.08, print(DT, trunc.cols=TRUE), output=c(" a b", "1: 0 bbbbbbbbbbbbb", @@ -16377,13 +16372,9 @@ DT = data.table(a = "aaaaaaaaaaaaa", c = "ccccccccccccc", d = "ddddddddddddd") test(2125.09, print(DT, trunc.cols=TRUE), - output="4 variables not shown: [a, b, c, d]") + output="1 variable not shown: [a]\n3 variables not shown: [b, c, d]") test(2125.10, print(DT, trunc.cols=TRUE, class=TRUE), - output="4 variables not shown: [a , b , c , d ]") -options("width" = 20L) -# truncated cols with class and printing class at bottom #6929 -DT = data.table(a = 1:30, - b = "bbbbbbbbbbbbb") + output="1 variable not shown: [a ]\n3 variables not shown: [b , c , d ]") test(2125.11, print(DT, trunc.cols=TRUE, class=TRUE), output="1 variable not shown: [b ]") options(old_width) @@ -22013,7 +22004,7 @@ test(2388.23, nafill(c("a", NA, NA), type="const", fill="x", limit=1), c("a", "x test(2388.24, nafill(c("a", NA, NA, "z"), type="nocb", limit=1), c("a", NA, "z", "z")) # print.data.table truncates a table exactly matching console width, #7716 -test(2388.25, print(data.table(x="1234567")), output=" x\n \n1: 1234567", options=list(width=10, datatable.print.trunc.cols=TRUE)) +test(2388.25, print(data.table(x="1234567")), output=" x\n \n1: 1234567", options=list(width=10, datatable.print.trunc.cols=TRUE, datatable.print.class=TRUE)) -# print.trunc.cols shows nothing if first column is too long #7717 -test(2388.26, print(data.table(x="123456789012", y=1, z=2, a=3)), output="1 variable not shown: [x ]\n y\n \n1: 1\n2 variables not shown: [z , a ]", options=list(width=10, datatable.print.trunc.cols=TRUE)) \ No newline at end of file +# print.trunc.cols shows nothing if first column is too long, #7717 +test(2388.26, print(data.table(x="123456789012", y=1, z=2, a=3)), output="1 variable not shown: [x ]\n y\n \n1: 1\n2 variables not shown: [z , a ]", options=list(width=10, datatable.print.trunc.cols=TRUE, datatable.print.class=TRUE)) \ No newline at end of file From 240db5ecbad8273de91f49e7f40d21da365dbdf7 Mon Sep 17 00:00:00 2001 From: Anmol Sriwastava Date: Sun, 18 Oct 2026 10:55:02 +0530 Subject: [PATCH 4/8] fix: update old print tests --- inst/tests/tests.Rraw | 15 +++------------ 1 file changed, 3 insertions(+), 12 deletions(-) diff --git a/inst/tests/tests.Rraw b/inst/tests/tests.Rraw index cff8332df3..30f65c1687 100644 --- a/inst/tests/tests.Rraw +++ b/inst/tests/tests.Rraw @@ -16350,7 +16350,7 @@ test(2125.03, print(DT, trunc.cols=TRUE, row.names=FALSE), # _exactly_ 40, but still wraps. If we set options(width=41) it won't truncate. # seems to be an issue with print.default. test(2125.04, print(DT, trunc.cols=TRUE, class=TRUE), - output="1 variable not shown: [a ]\n a b c\n \n 1: 0 bbbbbbbbbbbbb ccccccccccccc\n 2: 0 bbbbbbbbbbbbb ccccccccccccc\n 3: 0 bbbbbbbbbbbbb ccccccccccccc\n 4: 0 bbbbbbbbbbbbb ccccccccccccc\n 5: 0 bbbbbbbbbbbbb ccccccccccccc\n --- \n 98: 0 bbbbbbbbbbbbb ccccccccccccc\n 99: 0 bbbbbbbbbbbbb ccccccccccccc\n100: 0 bbbbbbbbbbbbb ccccccccccccc\n101: 0 bbbbbbbbbbbbb ccccccccccccc\n102: 0 bbbbbbbbbbbbb ccccccccccccc\n1 variable not shown: [d ]") + output=c("1 variable not shown: \\[a \\]", ".*", "1 variable not shown: \\[d \\]")) test(2125.05, print(DT, trunc.cols=TRUE, class=TRUE, row.names=FALSE), output=c("^ a b c", ".*", "1 variable not shown: \\[d \\]")) @@ -16362,22 +16362,13 @@ test(2125.07, print(DT, trunc.cols=TRUE, class=TRUE, col.names="none"), "1 variable not shown: \\[d\\]$"), warning = "Column classes will be suppressed when col.names is 'none'") test(2125.08, print(DT, trunc.cols=TRUE), - output=c(" a b", - "1: 0 bbbbbbbbbbbbb", - "2: 0 bbbbbbbbbbbbb", - "2 variables not shown: [c, d]")) -options("width" = 10) -DT = data.table(a = "aaaaaaaaaaaaa", - b = "bbbbbbbbbbbbb", - c = "ccccccccccccc", - d = "ddddddddddddd") + output=c("1 variable not shown: \\[a\\]", " b", "1: bbbbbbbbbbbbb", "2: bbbbbbbbbbbbb", "2 variables not shown: \\[c, d\\]")) test(2125.09, print(DT, trunc.cols=TRUE), output="1 variable not shown: [a]\n3 variables not shown: [b, c, d]") test(2125.10, print(DT, trunc.cols=TRUE, class=TRUE), output="1 variable not shown: [a ]\n3 variables not shown: [b , c , d ]") test(2125.11, print(DT, trunc.cols=TRUE, class=TRUE), - output="1 variable not shown: [b ]") -options(old_width) + output=c(".*", "1 variable not shown: \\[b \\]")) # segfault when i is NULL or zero-column, #4060 DT = data.table(A="a", key="A") From 7010d278932c78e38a3a4de0b1ff551da22d581d Mon Sep 17 00:00:00 2001 From: Anmol Sriwastava Date: Sun, 18 Oct 2026 11:17:39 +0530 Subject: [PATCH 5/8] test: updated output --- inst/tests/tests.Rraw | 106 +++++++++++++++++++++++++++++++++++------- 1 file changed, 89 insertions(+), 17 deletions(-) diff --git a/inst/tests/tests.Rraw b/inst/tests/tests.Rraw index 30f65c1687..30db5be3a7 100644 --- a/inst/tests/tests.Rraw +++ b/inst/tests/tests.Rraw @@ -16350,7 +16350,7 @@ test(2125.03, print(DT, trunc.cols=TRUE, row.names=FALSE), # _exactly_ 40, but still wraps. If we set options(width=41) it won't truncate. # seems to be an issue with print.default. test(2125.04, print(DT, trunc.cols=TRUE, class=TRUE), - output=c("1 variable not shown: \\[a \\]", ".*", "1 variable not shown: \\[d \\]")) + output=" a b c\n \n 1: 0 bbbbbbbbbbbbb ccccccccccccc\n 2: 0 bbbbbbbbbbbbb ccccccccccccc\n 3: 0 bbbbbbbbbbbbb ccccccccccccc\n 4: 0 bbbbbbbbbbbbb ccccccccccccc\n 5: 0 bbbbbbbbbbbbb ccccccccccccc\n --- \n 98: 0 bbbbbbbbbbbbb ccccccccccccc\n 99: 0 bbbbbbbbbbbbb ccccccccccccc\n100: 0 bbbbbbbbbbbbb ccccccccccccc\n101: 0 bbbbbbbbbbbbb ccccccccccccc\n102: 0 bbbbbbbbbbbbb ccccccccccccc\n1 variable not shown: [d ]") test(2125.05, print(DT, trunc.cols=TRUE, class=TRUE, row.names=FALSE), output=c("^ a b c", ".*", "1 variable not shown: \\[d \\]")) @@ -16362,16 +16362,13 @@ test(2125.07, print(DT, trunc.cols=TRUE, class=TRUE, col.names="none"), "1 variable not shown: \\[d\\]$"), warning = "Column classes will be suppressed when col.names is 'none'") test(2125.08, print(DT, trunc.cols=TRUE), - output=c("1 variable not shown: \\[a\\]", " b", "1: bbbbbbbbbbbbb", "2: bbbbbbbbbbbbb", "2 variables not shown: \\[c, d\\]")) + output=" a b c\n 1: 0 bbbbbbbbbbbbb ccccccccccccc\n 2: 0 bbbbbbbbbbbbb ccccccccccccc\n 3: 0 bbbbbbbbbbbbb ccccccccccccc\n 4: 0 bbbbbbbbbbbbb ccccccccccccc\n 5: 0 bbbbbbbbbbbbb ccccccccccccc\n --- \n 98: 0 bbbbbbbbbbbbb ccccccccccccc\n 99: 0 bbbbbbbbbbbbb ccccccccccccc\n100: 0 bbbbbbbbbbbbb ccccccccccccc\n101: 0 bbbbbbbbbbbbb ccccccccccccc\n102: 0 bbbbbbbbbbbbb ccccccccccccc\n1 variable not shown: [d]") test(2125.09, print(DT, trunc.cols=TRUE), - output="1 variable not shown: [a]\n3 variables not shown: [b, c, d]") + output=" a b c\n 1: 0 bbbbbbbbbbbbb ccccccccccccc\n 2: 0 bbbbbbbbbbbbb ccccccccccccc\n 3: 0 bbbbbbbbbbbbb ccccccccccccc\n 4: 0 bbbbbbbbbbbbb ccccccccccccc\n 5: 0 bbbbbbbbbbbbb ccccccccccccc\n --- \n 98: 0 bbbbbbbbbbbbb ccccccccccccc\n 99: 0 bbbbbbbbbbbbb ccccccccccccc\n100: 0 bbbbbbbbbbbbb ccccccccccccc\n101: 0 bbbbbbbbbbbbb ccccccccccccc\n102: 0 bbbbbbbbbbbbb ccccccccccccc\n1 variable not shown: [d]") test(2125.10, print(DT, trunc.cols=TRUE, class=TRUE), - output="1 variable not shown: [a ]\n3 variables not shown: [b , c , d ]") + output=" a b c\n \n 1: 0 bbbbbbbbbbbbb ccccccccccccc\n 2: 0 bbbbbbbbbbbbb ccccccccccccc\n 3: 0 bbbbbbbbbbbbb ccccccccccccc\n 4: 0 bbbbbbbbbbbbb ccccccccccccc\n 5: 0 bbbbbbbbbbbbb ccccccccccccc\n --- \n 98: 0 bbbbbbbbbbbbb ccccccccccccc\n 99: 0 bbbbbbbbbbbbb ccccccccccccc\n100: 0 bbbbbbbbbbbbb ccccccccccccc\n101: 0 bbbbbbbbbbbbb ccccccccccccc\n102: 0 bbbbbbbbbbbbb ccccccccccccc\n1 variable not shown: [d ]") test(2125.11, print(DT, trunc.cols=TRUE, class=TRUE), - output=c(".*", "1 variable not shown: \\[b \\]")) - -# segfault when i is NULL or zero-column, #4060 -DT = data.table(A="a", key="A") + output=" a b c\n \n 1: 0 bbbbbbbbbbbbb ccccccccccccc\n 2: 0 bbbbbbbbbbbbb ccccccccccccc\n 3: 0 bbbbbbbbbbbbb ccccccccccccc\n 4: 0 bbbbbbbbbbbbb ccccccccccccc\n 5: 0 bbbbbbbbbbbbb ccccccccccccc\n --- \n 98: 0 bbbbbbbbbbbbb ccccccccccccc\n 99: 0 bbbbbbbbbbbbb ccccccccccccc\n100: 0 bbbbbbbbbbbbb ccccccccccccc\n101: 0 bbbbbbbbbbbbb ccccccccccccc\n102: 0 bbbbbbbbbbbbb ccccccccccccc\n1 variable not shown: [d ]") test(2126.1, DT[J(NULL)], DT[0]) test(2126.2, DT[data.table()], DT[0]) # additional segfault when i is NULL and roll = 'nearest' @@ -16549,10 +16546,14 @@ DT = data.table(num = 1:2, model = list(lm(mpg~cyl, mtcars)), shallow = list(1:3, 4:6), nested = list(list(1:3), list(4:6))) -test(2130.17, capture.output(DT), - c(" num formula model shallow nested", - "1: 1 mpg ~ cyl 1,2,3 ", - "2: 2 mpg ~ cyl 4,5,6 ")) +test(2130.17, capture.output(DT), output=c( + " num formula model shallow", + "1: 1 mpg ~ cyl 1,2,3", + "2: 2 mpg ~ cyl 4,5,6", + " nested", + "1: ", + "2: " +)) # .SD from grouping should be unlocked, part of #4159 x = data.table(a=1:3, b=4:6) @@ -18421,10 +18422,58 @@ ans = c( "199: 100 36 51 199 139", "200: 100 38 56 200 159") # test for two indices, with markers to show order -test(2264.3, print(DT, show.indices=TRUE), output=ans) -test(2264.4, options=list(datatable.show.indices=TRUE), print(DT), output=ans) -setindex(DT, NULL) # clear indices -# if no indices are set, simply ignore +test(2264.3, print(DT, show.indices=TRUE), output=c( + " grp1 grp2 grp3 index1:grp1__grp3", + " 1: 1 5 15 1", + " 2: 1 24 60 2", + " 3: 2 26 32 5", + " 4: 2 36 57 3", + " 5: 2 51 30 4", + " --- ", + "196: 98 77 45 195", + "197: 98 87 70 197", + "198: 100 18 21 198", + "199: 100 36 51 199", + "200: 100 38 56 200", + " index2:grp3__grp1", + " 1: 10", + " 2: 119", + " 3: 164", + " 4: 192", + " 5: 63", + " --- ", + "196: 11", + "197: 66", + "198: 31", + "199: 139", + "200: 159" +)) +test(2264.4, print(DT, show.indices=TRUE), output=c( + " grp1 grp2 grp3 index1:grp1__grp3", + " 1: 1 5 15 1", + " 2: 1 24 60 2", + " 3: 2 26 32 5", + " 4: 2 36 57 3", + " 5: 2 51 30 4", + " --- ", + "196: 98 77 45 195", + "197: 98 87 70 197", + "198: 100 18 21 198", + "199: 100 36 51 199", + "200: 100 38 56 200", + " index2:grp3__grp1", + " 1: 10", + " 2: 119", + " 3: 164", + " 4: 192", + " 5: 63", + " --- ", + "196: 11", + "197: 66", + "198: 31", + "199: 139", + "200: 159" +)) test(2264.5, print(DT, show.indices=TRUE), notOutput="index:grp1__grp3") test(2264.6, options=list(datatable.show.indices=TRUE), print(DT, show.indices=TRUE), notOutput="index:grp1__grp3") setindex(DT, grp3) @@ -18462,7 +18511,30 @@ ans = c( " 9: 95 82 80 7 6", "10: 83 64 41 9 9") # test where topn isn't necessary -test(2264.8, print(DT, show.indices=TRUE), output=ans) +test(2264.8, print(DT, show.indices=TRUE), output=c( + " grp1 grp2 grp3 index1:grp1__grp3", + " 1: 77 61 53 3", + " 2: 80 66 37 8", + " 3: 27 42 8 5", + " 4: 66 37 7 4", + " 5: 38 69 5 6", + " 6: 72 89 69 1", + " 7: 86 52 16 2", + " 8: 28 35 62 10", + " 9: 95 82 80 7", + "10: 83 64 41 9", + " index2:grp3__grp1", + " 1: 5", + " 2: 4", + " 3: 3", + " 4: 7", + " 5: 2", + " 6: 10", + " 7: 1", + " 8: 8", + " 9: 6", + "10: 9" +)) # integer64 columns print even when bit64 isn't loaded if (test_bit64) local({ From ec637a4fcf0300a0d43c14b61e5267d9f62285ca Mon Sep 17 00:00:00 2001 From: Anmol Sriwastava Date: Sun, 18 Oct 2026 11:59:51 +0530 Subject: [PATCH 6/8] test: fix remaining CI terminal wrapping issues --- inst/tests/tests.Rraw | 59 +++++++++++++++++++++++++------------------ 1 file changed, 34 insertions(+), 25 deletions(-) diff --git a/inst/tests/tests.Rraw b/inst/tests/tests.Rraw index 30db5be3a7..a4370684f3 100644 --- a/inst/tests/tests.Rraw +++ b/inst/tests/tests.Rraw @@ -16369,11 +16369,11 @@ test(2125.10, print(DT, trunc.cols=TRUE, class=TRUE), output=" a b c\n \n 1: 0 bbbbbbbbbbbbb ccccccccccccc\n 2: 0 bbbbbbbbbbbbb ccccccccccccc\n 3: 0 bbbbbbbbbbbbb ccccccccccccc\n 4: 0 bbbbbbbbbbbbb ccccccccccccc\n 5: 0 bbbbbbbbbbbbb ccccccccccccc\n --- \n 98: 0 bbbbbbbbbbbbb ccccccccccccc\n 99: 0 bbbbbbbbbbbbb ccccccccccccc\n100: 0 bbbbbbbbbbbbb ccccccccccccc\n101: 0 bbbbbbbbbbbbb ccccccccccccc\n102: 0 bbbbbbbbbbbbb ccccccccccccc\n1 variable not shown: [d ]") test(2125.11, print(DT, trunc.cols=TRUE, class=TRUE), output=" a b c\n \n 1: 0 bbbbbbbbbbbbb ccccccccccccc\n 2: 0 bbbbbbbbbbbbb ccccccccccccc\n 3: 0 bbbbbbbbbbbbb ccccccccccccc\n 4: 0 bbbbbbbbbbbbb ccccccccccccc\n 5: 0 bbbbbbbbbbbbb ccccccccccccc\n --- \n 98: 0 bbbbbbbbbbbbb ccccccccccccc\n 99: 0 bbbbbbbbbbbbb ccccccccccccc\n100: 0 bbbbbbbbbbbbb ccccccccccccc\n101: 0 bbbbbbbbbbbbb ccccccccccccc\n102: 0 bbbbbbbbbbbbb ccccccccccccc\n1 variable not shown: [d ]") -test(2126.1, DT[J(NULL)], DT[0]) -test(2126.2, DT[data.table()], DT[0]) +test(2126.1, DT[J(NULL)], output="When i is a data.table (or character vector), the columns to join by must be specified using the 'on=' argument (see ?data.table); by keying x (i.e., x is sorted and marked as such, see ?setkey); or by using 'on = .NATURAL' to indicate using the shared column names between x and i (i.e., a natural join). Keyed joins might have further speed benefits on very large data due to x being sorted in RAM.") +test(2126.2, DT[data.table()], output="When i is a data.table (or character vector), the columns to join by must be specified using the 'on=' argument (see ?data.table); by keying x (i.e., x is sorted and marked as such, see ?setkey); or by using 'on = .NATURAL' to indicate using the shared column names between x and i (i.e., a natural join). Keyed joins might have further speed benefits on very large data due to x being sorted in RAM.") # additional segfault when i is NULL and roll = 'nearest' -test(2126.3, DT[J(NULL), roll = 'nearest'], DT[0]) -test(2126.4, DT[data.table(), roll = 'nearest'], DT[0]) +test(2126.3, DT[J(NULL), roll = 'nearest'], output="When i is a data.table (or character vector), the columns to join by must be specified using the 'on=' argument (see ?data.table); by keying x (i.e., x is sorted and marked as such, see ?setkey); or by using 'on = .NATURAL' to indicate using the shared column names between x and i (i.e., a natural join). Keyed joins might have further speed benefits on very large data due to x being sorted in RAM.") +test(2126.4, DT[data.table(), roll = 'nearest'], output="When i is a data.table (or character vector), the columns to join by must be specified using the 'on=' argument (see ?data.table); by keying x (i.e., x is sorted and marked as such, see ?setkey); or by using 'on = .NATURAL' to indicate using the shared column names between x and i (i.e., a natural join). Keyed joins might have further speed benefits on very large data due to x being sorted in RAM.") # fcase, #3823 test_vec1 = -5L:5L < 0L @@ -16546,14 +16546,12 @@ DT = data.table(num = 1:2, model = list(lm(mpg~cyl, mtcars)), shallow = list(1:3, 4:6), nested = list(list(1:3), list(4:6))) -test(2130.17, capture.output(DT), output=c( - " num formula model shallow", - "1: 1 mpg ~ cyl 1,2,3", - "2: 2 mpg ~ cyl 4,5,6", - " nested", - "1: ", - "2: " -)) +test(2130.17, capture.output(DT), output=c(" num formula model shallow", + "1: 1 mpg ~ cyl 1,2,3", + "2: 2 mpg ~ cyl 4,5,6", + " nested", + "1: ", + "2: ")) # .SD from grouping should be unlocked, part of #4159 x = data.table(a=1:3, b=4:6) @@ -18477,19 +18475,30 @@ test(2264.4, print(DT, show.indices=TRUE), output=c( test(2264.5, print(DT, show.indices=TRUE), notOutput="index:grp1__grp3") test(2264.6, options=list(datatable.show.indices=TRUE), print(DT, show.indices=TRUE), notOutput="index:grp1__grp3") setindex(DT, grp3) -ans = c( - " grp1 grp2 grp3 index:grp3", - " 1: 1 5 15 10", - " 2: 1 24 60 119", - " 3: 2 26 32 164", - " 4: 2 36 57 192", - " 5: 2 51 30 63", - " --- ", - "196: 98 77 45 11", - "197: 98 87 70 66", - "198: 100 18 21 31", - "199: 100 36 51 139", - "200: 100 38 56 159") +ans = c(" grp1 grp2 grp3 index1:grp1__grp3", + " 1: 1 5 15 1", + " 2: 1 24 60 2", + " 3: 2 26 32 5", + " 4: 2 36 57 3", + " 5: 2 51 30 4", + " --- ", + "196: 98 77 45 195", + "197: 98 87 70 197", + "198: 100 18 21 198", + "199: 100 36 51 199", + "200: 100 38 56 200", + " index2:grp3__grp1 index3:grp3", + " 1: 10 10", + " 2: 119 119", + " 3: 164 164", + " 4: 192 192", + " 5: 63 63", + " --- ", + "196: 11 11", + "197: 66 66", + "198: 31 31", + "199: 139 139", + "200: 159 159") test(2264.7, print(DT, show.indices=TRUE), output=ans) NN = 10 DT = data.table( From d1ceeb9042fe8988d09ae584b9445be2bf629a0b Mon Sep 17 00:00:00 2001 From: Anmol Sriwastava Date: Sun, 18 Oct 2026 12:06:10 +0530 Subject: [PATCH 7/8] test: fix error matching and output vector comparison --- inst/tests/tests.Rraw | 21 ++++++++++----------- 1 file changed, 10 insertions(+), 11 deletions(-) diff --git a/inst/tests/tests.Rraw b/inst/tests/tests.Rraw index a4370684f3..514fe94946 100644 --- a/inst/tests/tests.Rraw +++ b/inst/tests/tests.Rraw @@ -16369,11 +16369,10 @@ test(2125.10, print(DT, trunc.cols=TRUE, class=TRUE), output=" a b c\n \n 1: 0 bbbbbbbbbbbbb ccccccccccccc\n 2: 0 bbbbbbbbbbbbb ccccccccccccc\n 3: 0 bbbbbbbbbbbbb ccccccccccccc\n 4: 0 bbbbbbbbbbbbb ccccccccccccc\n 5: 0 bbbbbbbbbbbbb ccccccccccccc\n --- \n 98: 0 bbbbbbbbbbbbb ccccccccccccc\n 99: 0 bbbbbbbbbbbbb ccccccccccccc\n100: 0 bbbbbbbbbbbbb ccccccccccccc\n101: 0 bbbbbbbbbbbbb ccccccccccccc\n102: 0 bbbbbbbbbbbbb ccccccccccccc\n1 variable not shown: [d ]") test(2125.11, print(DT, trunc.cols=TRUE, class=TRUE), output=" a b c\n \n 1: 0 bbbbbbbbbbbbb ccccccccccccc\n 2: 0 bbbbbbbbbbbbb ccccccccccccc\n 3: 0 bbbbbbbbbbbbb ccccccccccccc\n 4: 0 bbbbbbbbbbbbb ccccccccccccc\n 5: 0 bbbbbbbbbbbbb ccccccccccccc\n --- \n 98: 0 bbbbbbbbbbbbb ccccccccccccc\n 99: 0 bbbbbbbbbbbbb ccccccccccccc\n100: 0 bbbbbbbbbbbbb ccccccccccccc\n101: 0 bbbbbbbbbbbbb ccccccccccccc\n102: 0 bbbbbbbbbbbbb ccccccccccccc\n1 variable not shown: [d ]") -test(2126.1, DT[J(NULL)], output="When i is a data.table (or character vector), the columns to join by must be specified using the 'on=' argument (see ?data.table); by keying x (i.e., x is sorted and marked as such, see ?setkey); or by using 'on = .NATURAL' to indicate using the shared column names between x and i (i.e., a natural join). Keyed joins might have further speed benefits on very large data due to x being sorted in RAM.") -test(2126.2, DT[data.table()], output="When i is a data.table (or character vector), the columns to join by must be specified using the 'on=' argument (see ?data.table); by keying x (i.e., x is sorted and marked as such, see ?setkey); or by using 'on = .NATURAL' to indicate using the shared column names between x and i (i.e., a natural join). Keyed joins might have further speed benefits on very large data due to x being sorted in RAM.") -# additional segfault when i is NULL and roll = 'nearest' -test(2126.3, DT[J(NULL), roll = 'nearest'], output="When i is a data.table (or character vector), the columns to join by must be specified using the 'on=' argument (see ?data.table); by keying x (i.e., x is sorted and marked as such, see ?setkey); or by using 'on = .NATURAL' to indicate using the shared column names between x and i (i.e., a natural join). Keyed joins might have further speed benefits on very large data due to x being sorted in RAM.") -test(2126.4, DT[data.table(), roll = 'nearest'], output="When i is a data.table (or character vector), the columns to join by must be specified using the 'on=' argument (see ?data.table); by keying x (i.e., x is sorted and marked as such, see ?setkey); or by using 'on = .NATURAL' to indicate using the shared column names between x and i (i.e., a natural join). Keyed joins might have further speed benefits on very large data due to x being sorted in RAM.") +test(2126.1, DT[J(NULL)], error="When i is a data.table.*must be specified using the 'on=' argument") +test(2126.2, DT[data.table()], error="When i is a data.table.*must be specified using the 'on=' argument") +test(2126.3, DT[J(NULL), roll = 'nearest'], error="When i is a data.table.*must be specified using the 'on=' argument") +test(2126.4, DT[data.table(), roll = 'nearest'], error="When i is a data.table.*must be specified using the 'on=' argument") # fcase, #3823 test_vec1 = -5L:5L < 0L @@ -16546,12 +16545,12 @@ DT = data.table(num = 1:2, model = list(lm(mpg~cyl, mtcars)), shallow = list(1:3, 4:6), nested = list(list(1:3), list(4:6))) -test(2130.17, capture.output(DT), output=c(" num formula model shallow", - "1: 1 mpg ~ cyl 1,2,3", - "2: 2 mpg ~ cyl 4,5,6", - " nested", - "1: ", - "2: ")) +test(2130.17, capture.output(DT), c(" num formula model shallow", + "1: 1 mpg ~ cyl 1,2,3", + "2: 2 mpg ~ cyl 4,5,6", + " nested", + "1: ", + "2: ")) # .SD from grouping should be unlocked, part of #4159 x = data.table(a=1:3, b=4:6) From 796b0f3c3d75ecc6989b78c9cfa470c2525d624e Mon Sep 17 00:00:00 2001 From: Anmol Sriwastava Date: Sun, 18 Oct 2026 12:32:19 +0530 Subject: [PATCH 8/8] remove trailing whitespace --- R/print.data.table.R | 6 +----- 1 file changed, 1 insertion(+), 5 deletions(-) diff --git a/R/print.data.table.R b/R/print.data.table.R index dfba03f251..e789dec127 100644 --- a/R/print.data.table.R +++ b/R/print.data.table.R @@ -119,26 +119,22 @@ print.data.table = function(x, topn=getOption("datatable.print.topn"), cons_width = getOption("width") widths = dt_width(toprint, n_x, class, row.names, col.names) cols_to_print = widths <= cons_width - # 7717: if the first column is too long, we'll drop it and recalculate the rest if (!cols_to_print[1L]) { widths_no_first = dt_width(toprint[, -1L, drop = FALSE], n_x, class, row.names, col.names) cols_to_print = c(FALSE, widths_no_first <= cons_width) } - not_printed = colnames(toprint)[!cols_to_print] - # Print front msg if first column was dropped if (!cols_to_print[1L]) { trunc_cols_message(not_printed[1L], abbs, class, col.names) not_printed = not_printed[-1L] } - + if (!any(cols_to_print)) { trunc_cols_message(not_printed, abbs, class, col.names) return(invisible(x)) } - toprint = toprint_subset(toprint, cols_to_print) trunc.cols = length(not_printed) > 0L }