Skip to content

Commit 548410d

Browse files
Fix: Ensure column widths are data-driven when col.names = "none" in print.data.table (#7130)
* added condition * indentation * news.md --------- Co-authored-by: Michael Chirico <[email protected]>
1 parent 038e7f8 commit 548410d

File tree

3 files changed

+12
-0
lines changed

3 files changed

+12
-0
lines changed

NEWS.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -84,6 +84,8 @@
8484
8585
20. `droplevels()` works on 0-row data.tables, [#7043](https://github.com/Rdatatable/data.table/issues/7043). The result will have factor columns `factor(character())`, consistent with the data.frame method. Thanks @advieser for the report and @MichaelChirico for the fix.
8686
87+
21. `print(..., col.names = 'none')` now correctly adapts column widths to the data content, ignoring the original column names and producing a more compact output, [#6882](https://github.com/Rdatatable/data.table/issues/6882). Thanks to @brooksambrose for the report and @venom1204 for the PR.
88+
8789
### NOTES
8890
8991
1. Continued work to remove non-API C functions, [#6180](https://github.com/Rdatatable/data.table/issues/6180). Thanks Ivan Krylov for the PRs and for writing a clear and concise guide about the R API: https://aitap.codeberg.page/R-api/.

R/print.data.table.R

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -141,6 +141,8 @@ print.data.table = function(x, topn=getOption("datatable.print.topn"),
141141
print_default(toprint)
142142
return(invisible(x))
143143
}
144+
if (col.names == "none")
145+
colnames(toprint) = rep.int("", ncol(toprint))
144146
if (nrow(toprint)>20L && col.names == "auto")
145147
# repeat colnames at the bottom if over 20 rows so you don't have to scroll up to see them
146148
# option to shut this off per request of Oleg Bondar on SO, #1482

inst/tests/tests.Rraw

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21365,3 +21365,11 @@ test(2328.1, levels(droplevels(DT)$f), character())
2136521365
DT[, i := integer()]
2136621366
DT[, f2 := factor()]
2136721367
test(2328.2, droplevels(DT), data.table(f=factor(), i=integer(), f2=factor()))
21368+
21369+
#6882 print() output with col.names="none"
21370+
dt = data.table(short = 1:3, verylongcolumnname = 4:6)
21371+
test(2329.1, print(dt, col.names = "none"), output = "1: 1 4\n2: 2 5\n3: 3 6\n")
21372+
dt = data.table(x = 123456, y = "wide_string")
21373+
test(2329.2, print(dt, col.names = "none"), output = "1: 123456 wide_string\n")
21374+
dt = data.table(a = NA_integer_, b = NaN)
21375+
test(2329.3, print(dt, col.names = "none"), output = "1: NA NaN\n")

0 commit comments

Comments
 (0)