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). 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 80df54b6aa..3edb7aceca 100644 --- a/inst/tests/tests.Rraw +++ b/inst/tests/tests.Rraw @@ -21775,3 +21775,8 @@ test(2377.44, copy(dt)[!(a < 5 & b != "d"), .ROW := NULL], dt[1:3]) 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")