Skip to content

bug fix: truncate wide columns in print.data.table #7788

Open
venom1204 wants to merge 8 commits into
masterfrom
issue771188
Open

bug fix: truncate wide columns in print.data.table #7788
venom1204 wants to merge 8 commits into
masterfrom
issue771188

Conversation

@venom1204

@venom1204 venom1204 commented Jun 10, 2026

Copy link
Copy Markdown
Contributor

closes #7718
sorry for the new pr ,as there was some error in the previous one

  • here is the summary of teh previous pr

the earlier pr mainly used a fixed getOption("width") - 5L style truncation approach which worked for some simple cases but failed once row labels became larger (for example 1000000:) because the full rendered line width was not being accounted for correctly.

  • in this updated implementation, the truncation width is now calculated dynamically using the actual row label width and console width instead of a fixed constant.
  • i also added a saftey handelling using allowNA=TRUE in nchar() calls to avoid invalid width failures during tests,while preserving thr original datatable.prettyprint.char.

with these changes the ouput now takes the full options(width) limit for the entire rendered line.
hi @joshhwuu @tdhock can you please have a look at it when you got time ,
thanks

@venom1204 venom1204 changed the title new pr bug fix: truncate wide columns in print.data.table Jun 10, 2026
@codecov

codecov Bot commented Jun 10, 2026

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 98.85%. Comparing base (d65e46f) to head (aa8c344).
⚠️ Report is 2 commits behind head on master.

Additional details and impacted files
@@           Coverage Diff           @@
##           master    #7788   +/-   ##
=======================================
  Coverage   98.85%   98.85%           
=======================================
  Files          87       87           
  Lines       17128    17137    +9     
=======================================
+ Hits        16932    16941    +9     
  Misses        196      196           

☔ 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 10, 2026

Copy link
Copy Markdown

No obvious timing issues in HEAD=issue771188
Comparison Plot

Generated via commit aa8c344

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

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

Comment thread inst/tests/tests.Rraw
Comment thread R/print.data.table.R Outdated
}

format_col.default = function(x, ...) {
dots = list(...)

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.

could you explain the motivation behind this dots = list(...) pattern? imo it makes the code a lot harder to read, would rather us be more specific about method contracts and declare it as a parameter

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.

it was done to avoid the codoc mismatch between teh doc and the code , now i have updated the doc and reverted it

Comment thread R/print.data.table.R Outdated
Comment thread R/print.data.table.R Outdated
Comment thread NEWS.md Outdated

11. `between()` now supports `Date` and `IDate` bounds with default `NAbounds=TRUE`, avoiding errors like "Not yet implemented NAbounds=TRUE for this non-numeric and non-character type" when date bounds contain `NA`, [#7281](https://github.com/Rdatatable/data.table/issues/7281). Thanks @grcatlin for the report and fix, and @ben-schwen and @aitap for assistance.

12. `print.data.table()` now correctly truncates long character columns and list-column summaries to avoid horizontal console overflow, [#7718](https://github.com/Rdatatable/data.table/issues/7718). When `datatable.prettyprint.char` is `NULL` (the default), the truncation limit is now dynamically calculated as `getOption("width") - 5L`. Thanks @tdhock for the report and @venom1204 for the fix.

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.

is this still true? also we may not want to be too verbose about implementation details here

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.

sorry for the news entry I simply gave the previous file forgot to modify it.

@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.

this looks good, but can you please add some examples in Rd and PR comments (with output) ?

@venom1204

Copy link
Copy Markdown
Contributor Author

this looks good, but can you please add some examples in Rd and PR comments (with output) ?

> library(data.table)
data.table 1.18.99 IN DEVELOPMENT built 2026-06-10 20:33:59 UTC; root using 6 threads (see ?getDTthreads).  Latest news: r-datatable.com
> 
> options(width = 20, datatable.prettyprint.char = NULL)
data.table(x = "12345678901234567890")
                   x
              <char>
1: 12345678901234...
> options(width = 25, datatable.prettyprint.char = NULL)
DT = data.table(x = rep("ABCDEFGHIJKLMNOPQRSTUVWXYZ", 1000000))
print(DT, topn = 1)
                        x
                   <char>
      1: ABCDEFGHIJKLM...
     ---                 
1000000: ABCDEFGHIJKLM...

hi @tdhock are these examples good or should i do it for some more examples.
thanks

Comment thread NEWS.md Outdated

11. `between()` now supports `Date` and `IDate` bounds with default `NAbounds=TRUE`, avoiding errors like "Not yet implemented NAbounds=TRUE for this non-numeric and non-character type" when date bounds contain `NA`, [#7281](https://github.com/Rdatatable/data.table/issues/7281). Thanks @grcatlin for the report and fix, and @ben-schwen and @aitap for assistance.

12. `print.data.table()` now correctly truncates long character columns and list-column summaries to avoid horizontal console overflow, [#7718](https://github.com/Rdatatable/data.table/issues/7718). When `datatable.prettyprint.char` is `NULL` (the default), the truncation limit is now dynamically calculated based on the available console width. Thanks @tdhock for the report and @venom1204 for the fix.

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.

instead of saying "now correctly", maybe we can say "now by default"? WDYT

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.

yah i think that sounds good and more descriptive.

@venom1204 venom1204 requested review from joshhwuu and tdhock June 11, 2026 18:51
Comment thread man/print.data.table.Rd
Comment on lines +141 to +145
data.table(x = "abcdefghijklmnopqrstuvwxyz", L = list(1:25))

# Dynamic truncation: Content shrinks as row labels grow
print(data.table(x = rep("ABCDEFGHIJKLMNOPQRSTUVWXYZ", 1e6)), topn = 1)
options(old)

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 you please show us the output of these commands in a PR comment?

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.

> library(data.table)
data.table 1.18.99 IN DEVELOPMENT built 2026-06-12 15:39:21 UTC; root using 6 threads (see ?getDTthreads).  Latest news: r-datatable.com
> options(width = 25, datatable.prettyprint.char = NULL)
> data.table(x = "abcdefghijklmnopqrstuvwxyz", L = list(1:25))
                        x
                   <char>
1: abcdefghijklmnopqrs...
                     L
                <list>
1: 1,2,3,4,5,6,...[25]
> print(data.table(x = rep("ABCDEFGHIJKLMNOPQRSTUVWXYZ", 1e6)), topn = 1)
                        x
                   <char>
      1: ABCDEFGHIJKLM...
     ---                 
1000000: ABCDEFGHIJKLM...

here is what i got as a result

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.

print should abbreviate columns larger than options(width)?

3 participants