Skip to content

Fix truncation of long column names in print.data.table()#7802

Open
venom1204 wants to merge 14 commits into
masterfrom
issue7797
Open

Fix truncation of long column names in print.data.table()#7802
venom1204 wants to merge 14 commits into
masterfrom
issue7797

Conversation

@venom1204

Copy link
Copy Markdown
Contributor

closes #7797

apply width based truncation to long column names when printing data.tables, ensuring that table headers and hidden-column footers respect the available console width.

@codecov

codecov Bot commented Jun 24, 2026

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 99.01%. Comparing base (fc60d3c) to head (5d62f50).

Additional details and impacted files
@@           Coverage Diff           @@
##           master    #7802   +/-   ##
=======================================
  Coverage   99.01%   99.01%           
=======================================
  Files          88       88           
  Lines       17219    17223    +4     
=======================================
+ Hits        17050    17054    +4     
  Misses        169      169           

☔ View full report in Codecov by Harness.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

@github-actions

github-actions Bot commented Jun 24, 2026

Copy link
Copy Markdown
  • HEAD=issue7797 much slower for transform improved in #5493
    Comparison Plot

Generated via commit 5d62f50

Download link for the artifact containing the test results: ↓ atime-results.zip

Task Duration
R setup and installing dependencies 2 minutes and 45 seconds
Installing different package versions 47 seconds
Running and plotting the test cases 5 minutes and 27 seconds

@venom1204 venom1204 requested review from joshhwuu and tdhock June 24, 2026 20:06
Comment thread inst/tests/tests.Rraw Outdated

#7797 long column names go past width
test(2377.1, print(data.table(abcdefghijklmnopqrstuvwxyz=1)), output="abcdefghijklmn...", options=list(width=20))
test(2377.2, print(data.table(abcdefghijklmnopqrstuvwxyz=1)), output="1 variable not shown: \\[abcdefghijklmn... <num>\\]", options=list(width=20, datatable.print.trunc.cols=TRUE, datatable.print.class=TRUE))

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

please add a test with more than one column.

  • 3 cols: two too long, one not
  • 4 cols: one too long, next not, next too long, next not
  • etc

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

i added two tests , are they satisfying what you were excpecting.
thanks.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this is better but the test output has regex so difficult for me to see what it actually prints as, can you please add the output of these tests in a PR comment?

Comment thread inst/tests/tests.Rraw Outdated
test(2377.1, print(data.table(abcdefghijklmnopqrstuvwxyz=1)), output="abcdefghijklmn...", options=list(width=20))
test(2377.2, print(data.table(abcdefghijklmnopqrstuvwxyz=1)), output="1 variable not shown: \\[abcdefghijklmn... <num>\\]", options=list(width=20, datatable.print.trunc.cols=TRUE, datatable.print.class=TRUE))
test(2377.3, print(data.table(abcdefghijklmnopqrst=1)), output="abcdefghijklmnopqrst", options=list(width=30))
test(2377.4, print(data.table(abcdefghijklmnopqrstuvwxyz=1, zyxwvutsrqponmlkjihgfedcba=2)), output="zyxwvutsrqponm...", options=list(width=40, datatable.print.trunc.cols=TRUE))

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

it looks like we're only asserting the footer output here? can we make the assertions stronger?

@tdhock tdhock left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

good

Comment thread R/print.data.table.R Outdated
Comment on lines +63 to +64
e_trunc = getOption("datatable.prettyprint.char") %||% (getOption("width") - 5L)
t_names = char.trunc(head(names(x), 6L), trunc.char = e_trunc)

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

can these 5L and 6L get put in variables with informative names so we can understand where they come from? or please at least add a comment to explain?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

just wanted to ask on thing that should `datatable.prettyprint.char = Inf`` also disable truncation of column names, or should column names always respect the available print width?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this is what i got for the first twotests

> options(width=20)
print(data.table(abcdefghijklmnopqrstuvwxyz=1))
   abcdefghijklmn...
               <num>
1:                 1
> options(width=20,
        datatable.print.trunc.cols=TRUE,
        datatable.print.class=TRUE)
print(data.table(abcdefghijklmnopqrstuvwxyz=1))
1 variable not shown: [abcdefghijklmn... <num>]

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

for consistency and back compatibility, datatable.prettyprint.char = Inf should disable truncation of column names I think

Comment thread R/print.data.table.R Outdated
Comment on lines +96 to +97
rn_w = if (isTRUE(row.names)) nchar(as.character(max(rn))) + 2L else 0L
width_limit = max(0L, getOption("width") - rn_w - 3L)

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

same here please explain 0L 3L 2L?

Comment thread inst/tests/tests.Rraw Outdated

#7797 long column names go past width
test(2377.1, print(data.table(abcdefghijklmnopqrstuvwxyz=1)), output="abcdefghijklmn...", options=list(width=20))
test(2377.2, print(data.table(abcdefghijklmnopqrstuvwxyz=1)), output="1 variable not shown: \\[abcdefghijklmn... <num>\\]", options=list(width=20, datatable.print.trunc.cols=TRUE, datatable.print.class=TRUE))

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this is better but the test output has regex so difficult for me to see what it actually prints as, can you please add the output of these tests in a PR comment?

@venom1204 venom1204 requested a review from tdhock June 28, 2026 10:07
@venom1204 venom1204 requested a review from joshhwuu June 28, 2026 11:09

@tdhock tdhock left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

please add NEWS

@venom1204 venom1204 requested a review from tdhock June 29, 2026 18:29
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

long column names go past width

3 participants