From 06d18c1815639e7a84dea2819ea9ef946adfdcd2 Mon Sep 17 00:00:00 2001 From: Leonidas Zhak <70497898+LeonidasZhak@users.noreply.github.com> Date: Sun, 7 Jun 2026 13:47:15 +0800 Subject: [PATCH] fix: col.names='none' suppresses print completely (#7735) --- R/print.data.table.R | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) diff --git a/R/print.data.table.R b/R/print.data.table.R index 88ff4ea505..c812ba7ac6 100644 --- a/R/print.data.table.R +++ b/R/print.data.table.R @@ -126,8 +126,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 - cut_colnames(print(x, right=TRUE, quote=quote, na.print=na.print)) + if (col.names == "none") { + # #7735: blank column names in output directly instead of using cut_colnames, + # which also drops data rows lacking row-number colons (row.names=FALSE) + colnames(x) = rep.int("", ncol(x)) + writeLines(capture.output(print(x, right=TRUE, quote=quote, na.print=na.print))) + } else { + 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) } @@ -141,8 +147,6 @@ print.data.table = function(x, topn=getOption("datatable.print.topn"), print_default(toprint) return(invisible(x)) } - if (col.names == "none") - colnames(toprint) = rep.int("", ncol(toprint)) if (nrow(toprint)>20L && col.names == "auto") # repeat colnames at the bottom if over 20 rows so you don't have to scroll up to see them # option to shut this off per request of Oleg Bondar on SO, #1482