From 9c8500aa4d08b329b9116e278fd48fba8a4be329 Mon Sep 17 00:00:00 2001 From: venom1204 Date: Sun, 28 Jun 2026 19:22:33 +0000 Subject: [PATCH 1/5] updaetde logic --- R/print.data.table.R | 9 ++++++++- inst/tests/tests.Rraw | 5 +++++ 2 files changed, 13 insertions(+), 1 deletion(-) diff --git a/R/print.data.table.R b/R/print.data.table.R index e602f80d69..e9baf7a78e 100644 --- a/R/print.data.table.R +++ b/R/print.data.table.R @@ -131,7 +131,14 @@ print.data.table = function(x, topn=getOption("datatable.print.topn"), trunc.cols = length(not_printed) > 0L } print_default = function(x) { - if (col.names != "none") cut_colnames = identity + if (col.names != "none") { + cut_colnames = identity + } else if (isFALSE(row.names)) { + cut_colnames = function(x) { + out = capture.output(x) + if (length(out) > 0L) writeLines(out[-1L]) + } + } cut_colnames(print(x, right=TRUE, quote=quote, na.print=na.print)) # prints names of variables not shown in the print if (trunc.cols) trunc_cols_message(not_printed, abbs, class, col.names) diff --git a/inst/tests/tests.Rraw b/inst/tests/tests.Rraw index 3f201f975a..75fb0ec468 100644 --- a/inst/tests/tests.Rraw +++ b/inst/tests/tests.Rraw @@ -21683,3 +21683,8 @@ max_ppsize = local({ x = as.data.table(as.list(1:max_ppsize)) test(2376, rbindlist(list(x)), x) rm(x, max_ppsize) + +# #7735 col.names="none" should suppress only column headers, not data +test(2377.1, print(data.table(c1=1:2, c2=letters[1:2]), nrows=Inf, class=FALSE, row.names=FALSE, show.indices=FALSE, print_keys=FALSE, col.names="none"), output=" 1 a\n 2 b") +test(2377.2, print(data.table(x=1:3), class=FALSE, row.names=FALSE, col.names="none"), output=" 1\n 2\n 3") +test(2377.3, print(data.table(c1=1:3, c2=letters[1:3]), row.names=TRUE, class=FALSE, col.names="none"), output="1: 1 a\n2: 2 b\n3: 3 c") From 8f8613a4819495db075d20df37fcb2e2a2e4c0ed Mon Sep 17 00:00:00 2001 From: venom1204 Date: Mon, 29 Jun 2026 18:19:19 +0000 Subject: [PATCH 2/5] added news --- NEWS.md | 2 ++ 1 file changed, 2 insertions(+) diff --git a/NEWS.md b/NEWS.md index daa8151518..9f182939be 100644 --- a/NEWS.md +++ b/NEWS.md @@ -60,6 +60,8 @@ 13. `rbindlist()` (and therefore the `rbind()` method for `data.table`s) no longer raises an error upon encountering more than approximately 50000 columns in a list entry, [#7793](https://github.com/Rdatatable/data.table/issues/7793). The bug was introduced in `data.table` version 1.18.2.1. Thanks to @rickhelmus for the report and @aitap for the fix. +14. `print.data.table()` now correctly displays data when `col.names="none"` and `row.names=FALSE`, [#7735](https://github.com/Rdatatable/data.table/issues/7735). Previously, the output was entirely suppressed because the internal logic relied on row markers (e.g., `1:`) to identify data lines. Thanks to @jan-swissre for the report and @YourGitHubHandle for the fix. + ### Notes 1. {data.table} now depends on R 3.5.0 (2018). From 56acefcc4d28e5e55a044c1ab1477317db4d44ef Mon Sep 17 00:00:00 2001 From: venom1204 Date: Mon, 29 Jun 2026 18:41:51 +0000 Subject: [PATCH 3/5] .. --- inst/tests/tests.Rraw | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/inst/tests/tests.Rraw b/inst/tests/tests.Rraw index 489e624535..3edb7aceca 100644 --- a/inst/tests/tests.Rraw +++ b/inst/tests/tests.Rraw @@ -21777,6 +21777,6 @@ test(2377.91, truelength(dt$a), 0L) test(2377.92, {setallocrow(dt); truelength(dt$a)}, 3L) # #7735 col.names="none" should suppress only column headers, not data -test(2377.1, print(data.table(c1=1:2, c2=letters[1:2]), nrows=Inf, class=FALSE, row.names=FALSE, show.indices=FALSE, print_keys=FALSE, col.names="none"), output=" 1 a\n 2 b") -test(2377.2, print(data.table(x=1:3), class=FALSE, row.names=FALSE, col.names="none"), output=" 1\n 2\n 3") -test(2377.3, print(data.table(c1=1:3, c2=letters[1:3]), row.names=TRUE, class=FALSE, col.names="none"), output="1: 1 a\n2: 2 b\n3: 3 c") +test(2378.1, print(data.table(c1=1:2, c2=letters[1:2]), nrows=Inf, class=FALSE, row.names=FALSE, show.indices=FALSE, print_keys=FALSE, col.names="none"), output=" 1 a\n 2 b") +test(2378.2, print(data.table(x=1:3), class=FALSE, row.names=FALSE, col.names="none"), output=" 1\n 2\n 3") +test(2378.3, print(data.table(c1=1:3, c2=letters[1:3]), row.names=TRUE, class=FALSE, col.names="none"), output="1: 1 a\n2: 2 b\n3: 3 c") From 7d3c34095ace4961376050d1f384171534a193b4 Mon Sep 17 00:00:00 2001 From: Benjamin Schwendinger Date: Wed, 5 Aug 2026 10:54:07 +0200 Subject: [PATCH 4/5] fix PR and add tests --- NEWS.md | 2 +- R/print.data.table.R | 20 +++++++++----------- inst/tests/tests.Rraw | 26 +++++++++++++++++--------- 3 files changed, 27 insertions(+), 21 deletions(-) diff --git a/NEWS.md b/NEWS.md index 9f182939be..9d07873fda 100644 --- a/NEWS.md +++ b/NEWS.md @@ -60,7 +60,7 @@ 13. `rbindlist()` (and therefore the `rbind()` method for `data.table`s) no longer raises an error upon encountering more than approximately 50000 columns in a list entry, [#7793](https://github.com/Rdatatable/data.table/issues/7793). The bug was introduced in `data.table` version 1.18.2.1. Thanks to @rickhelmus for the report and @aitap for the fix. -14. `print.data.table()` now correctly displays data when `col.names="none"` and `row.names=FALSE`, [#7735](https://github.com/Rdatatable/data.table/issues/7735). Previously, the output was entirely suppressed because the internal logic relied on row markers (e.g., `1:`) to identify data lines. Thanks to @jan-swissre for the report and @YourGitHubHandle for the fix. +14. `print.data.table()` now correctly displays data when `col.names="none"` and `row.names=FALSE`, [#7735](https://github.com/Rdatatable/data.table/issues/7735). Thanks to @jan-swissre for the report and @venom1204 for the fix. ### Notes diff --git a/R/print.data.table.R b/R/print.data.table.R index e9baf7a78e..89576c9d2f 100644 --- a/R/print.data.table.R +++ b/R/print.data.table.R @@ -131,15 +131,8 @@ print.data.table = function(x, topn=getOption("datatable.print.topn"), trunc.cols = length(not_printed) > 0L } print_default = function(x) { - if (col.names != "none") { - cut_colnames = identity - } else if (isFALSE(row.names)) { - cut_colnames = function(x) { - out = capture.output(x) - if (length(out) > 0L) writeLines(out[-1L]) - } - } - cut_colnames(print(x, right=TRUE, quote=quote, na.print=na.print)) + if (col.names != "none") cut_colnames = function(x, nr) x + cut_colnames(print(x, right=TRUE, quote=quote, na.print=na.print), nrow(x)) # prints names of variables not shown in the print if (trunc.cols) trunc_cols_message(not_printed, abbs, class, col.names) } @@ -184,8 +177,13 @@ shouldPrint = function(x) { # for removing the head (column names) of matrix output entirely, # as opposed to printing a blank line, for excluding col.names per PR #1483 -# be sure to remove colnames from any row where they exist, #4270 -cut_colnames = function(x) writeLines(grepv("^\\s*(?:[0-9]+:|---)", capture.output(x))) +# print() splits a matrix too wide for the console into blocks, each one starting +# with its own line of column names; drop all of them, #4270, and don't rely on +# row names being present to identify the data lines, #7735 +cut_colnames = function(x, nr) { + out = capture.output(x) + writeLines(out[seq_along(out) %% (nr + 1L) != 1L]) +} # for printing the dims for list columns #3671; used by format.data.table() paste_dims = function(x) { diff --git a/inst/tests/tests.Rraw b/inst/tests/tests.Rraw index 3edb7aceca..b3802c57be 100644 --- a/inst/tests/tests.Rraw +++ b/inst/tests/tests.Rraw @@ -20936,11 +20936,11 @@ dt = data.table(a = NA_integer_, b = NaN) test(2329.3, print(dt, col.names = "none"), output = "1: NA NaN$") # Row name extraction from multiple vectors, #7136 -x <- 1:3 -y <- setNames(4:6, c("A", "B", "C")) +x <- 1:3 +y <- setNames(4:6, c("A", "B", "C")) test(2330.1, as.data.table(list(x, y), keep.rownames=TRUE), data.table(rn=c("A", "B", "C"), V1=1:3, V2=4:6)) test(2330.2, as.data.table(list(x, y), keep.rownames="custom"), data.table(custom=c("A", "B", "C"), V1=1:3, V2=4:6)) -test(2330.3, as.data.table(list(y, x), keep.rownames=TRUE), data.table(rn=c("A", "B", "C"), V1=4:6, V2=1:3)) +test(2330.3, as.data.table(list(y, x), keep.rownames=TRUE), data.table(rn=c("A", "B", "C"), V1=4:6, V2=1:3)) # Behavior under data.frame() test(2330.4, as.data.table(data.frame(x, y), keep.rownames=TRUE), data.table(rn=c("A", "B", "C"), x=1:3, y=4:6)) @@ -21241,7 +21241,7 @@ test(2341.22, fread('a,b # inline header comment\r\n1,2\r\n', comment.char = ' test(2341.230, fread('a b # trailing cmnt ', comment.char = '#', strip.white = FALSE, sep = ","), data.table(a="b ")) -test(2341.231, fread('a # trailing header cmnt +test(2341.231, fread('a # trailing header cmnt b ', comment.char = '#', strip.white = FALSE, sep = ","), data.table(`a `="b")) test(2341.232, fread('a @@ -21569,7 +21569,7 @@ xenv$N = list(a=1:5) xenv$DF = data.frame(a = 1:2) xenv$DF$b = data.table(c = 3:4, d = 5:6) test(2366.1, - tables(env=xenv, depth=1L, index=TRUE)[, .(NAME, NROW, NCOL, INDICES, KEY)], + tables(env=xenv, depth=1L, index=TRUE)[, .(NAME, NROW, NCOL, INDICES, KEY)], data.table( NAME = c("DF$b", "DT", "L[[1]]", "L[[2]]", "M$b"), NROW = c(2L, 1L, 3L, 4L, 3L), @@ -21776,7 +21776,15 @@ dt = data.table(a=1:3) test(2377.91, truelength(dt$a), 0L) test(2377.92, {setallocrow(dt); truelength(dt$a)}, 3L) -# #7735 col.names="none" should suppress only column headers, not data -test(2378.1, print(data.table(c1=1:2, c2=letters[1:2]), nrows=Inf, class=FALSE, row.names=FALSE, show.indices=FALSE, print_keys=FALSE, col.names="none"), output=" 1 a\n 2 b") -test(2378.2, print(data.table(x=1:3), class=FALSE, row.names=FALSE, col.names="none"), output=" 1\n 2\n 3") -test(2378.3, print(data.table(c1=1:3, c2=letters[1:3]), row.names=TRUE, class=FALSE, col.names="none"), output="1: 1 a\n2: 2 b\n3: 3 c") +# col.names="none" should suppress only the column names, not the data, #7735 +DT = data.table(c1=1:2, c2=letters[1:2]) +test(2378.1, print(DT, col.names="none", row.names=FALSE, class=FALSE), output=c(" 1 a\n 2 b")) +# also handle wide tables and other formattings +DT = data.table(a=strrep("a",20L), b=strrep("b",20L), c=strrep("c",20L)) +test(2378.2, options=list(width=40L), print(DT, col.names="none", row.names=FALSE, class=FALSE), + output=c(" aaaaaaaaaaaaaaaaaaaa\n bbbbbbbbbbbbbbbbbbbb\n cccccccccccccccccccc")) +DT = data.table(x=c(NA,"e","b","j","w",NA)) +test(2378.3, print(DT, na.print=".", topn=2, col.names="none", row.names=FALSE, class=FALSE), + output=c(" .\n e\n ---\n w\n .")) +DT = data.table(a=c("x\ny","z"), b=1:2) +test(2378.4, print(DT, col.names="none", row.names=FALSE, class=FALSE), output=c(" x\\ny 1\n z 2")) From 623a682383a966c434c80b2c2ffd0a59ecdea024 Mon Sep 17 00:00:00 2001 From: Benjamin Schwendinger Date: Wed, 5 Aug 2026 11:11:14 +0200 Subject: [PATCH 5/5] finish merge --- inst/tests/tests.Rraw | 4 ---- 1 file changed, 4 deletions(-) diff --git a/inst/tests/tests.Rraw b/inst/tests/tests.Rraw index 5456507f66..eff85b13c4 100644 --- a/inst/tests/tests.Rraw +++ b/inst/tests/tests.Rraw @@ -21610,11 +21610,7 @@ xenv$N = list(a=1:5) xenv$DF = data.frame(a = 1:2) xenv$DF$b = data.table(c = 3:4, d = 5:6) test(2366.1, -<<<<<<< HEAD - tables(env=xenv, depth=1L, index=TRUE)[, .(NAME, NROW, NCOL, INDICES, KEY)], -======= tables(env=xenv, depth=1L, index=TRUE, silent=TRUE)[, .(NAME, NROW, NCOL, INDICES, KEY)], ->>>>>>> master data.table( NAME = c("DF$b", "DT", "L[[1]]", "L[[2]]", "M$b"), NROW = c(2L, 1L, 3L, 4L, 3L),