Repository navigation
print col.names='none' does not affect column width #6882
Description
Activity
Hi @tdhock ,
I'd like to work on this issue — could you please assign this issue to me?Here’s my proposed solution:
I plan to modify the width calculation logic so that:- Column widths are based only on actual data content when col.names = "none".
- Width contributions from column names and class annotations are skipped in that case.
- Behavior remains unchanged when column names are printed normally.
This should result in a cleaner and more compact output when column names are omitted.
Let me know if this approach works, and I’ll move ahead with the implementation. Thanks!
Yes, go ahead @venom1204, that's the basic idea.
Reacted by venom1204hi @aitap ,
After further investigation, I found that the most robust solution is to explicitly set all column names to empty strings in the toprint object whencol.names = "none":if (col.names == "none") colnames(toprint) <- rep.int("", ncol(toprint))I plan to add this line in the print.data.table function, right after toprint is constructed (e.g., after
toprint = x[idx, ] or toprint = x), but before any formatting or width calculations. This ensures all downstream formatting uses empty column names, so column widths are determined solely by the data, fully resolving the issue.-
All tests, including edge cases, now pass and the output is compact and consistent.
-
Could you confirm if this approach is acceptable? Also, if there are any potential side effects or unrelated areas of the codebase that might be impacted by this change(right now there aren't any according to me)—especially ones I may not be aware of—please let me know. If approved, I’ll proceed with the implementation.
thank you.
-
Indeed that sounds good. Potentially it could just be included as a condition here:
data.table/R/print.data.table.R
Lines 94 to 96 in 2b7eb4c
if (is.null(names(x)) || !any(nzchar(names(x), keepNA=TRUE))) # fixes bug #97 and #545 colnames(toprint)=rep("", ncol(toprint)) - added a commit that references this issue
on May 22, 2026
In
print.data.tablewhen settingcol.names='none'I expected column widths to be sized according to their contents. Instead, the column widths are unchanged. Incidentally, when class is suppressed the column widths are different. I expect the behavior to be consistent between those two options.Created on 2025-03-24 with reprex v2.1.0