Skip to content

Adds optional column count display to print.data.table()#7791

Open
venom1204 wants to merge 14 commits into
masterfrom
issue6663
Open

Adds optional column count display to print.data.table()#7791
venom1204 wants to merge 14 commits into
masterfrom
issue6663

Conversation

@venom1204

Copy link
Copy Markdown
Contributor

closes #6663.
in this pr I

  • Added datatable.show.ncols option (default FALSE).
  • Added show.ncols support .
  • Added header output for total column count.
  • Integrated column count with trunc.cols=TRUE output.

hi @tdhock @joshhwuu can you please have a look when you get time.
thanks

@codecov

codecov Bot commented Jun 16, 2026

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 98.85%. Comparing base (deb9acc) to head (e697d45).

Additional details and impacted files
@@           Coverage Diff           @@
##           master    #7791   +/-   ##
=======================================
  Coverage   98.85%   98.85%           
=======================================
  Files          87       87           
  Lines       17140    17156   +16     
=======================================
+ Hits        16944    16960   +16     
  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 16, 2026

Copy link
Copy Markdown
  • HEAD=issue6663 much slower for transform improved in #5493
  • HEAD=issue6663 slower P<0.001 for DT[by] max regression fixed in #7480
    Comparison Plot

Generated via commit e697d45

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

Task Duration
R setup and installing dependencies 2 minutes and 44 seconds
Installing different package versions 23 seconds
Running and plotting the test cases 5 minutes and 25 seconds

@venom1204 venom1204 requested review from joshhwuu and tdhock June 16, 2026 16:56

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

looks good, please add NEWS

Comment thread R/print.data.table.R Outdated
cons_width = getOption("width")
cols_to_print = widths < cons_width
not_printed = colnames(toprint)[!cols_to_print]

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 remove empty lines

@venom1204 venom1204 requested a review from tdhock June 16, 2026 19:00
Comment thread inst/tests/tests.Rraw Outdated
test(2374.10, key(DT[, .(a.1, sum(val)), keyby=.(a, a)]), NULL)

#6663 Option to print the number of columns
test(2375.1, {options(datatable.show.ncols=TRUE); DT=as.data.table(iris); capture.output(print(DT))[1L]}, "Number of columns: 5")

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.

We have an options parameter in test, so please use it!

Please only use bracket blocks {} when it adds clarity, here it seems more complicated then using setup step.

Also you can set multiple options at once with options.

@venom1204 venom1204 requested a review from ben-schwen June 25, 2026 10:41

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

There seems to be a problem when trunc.cols and nrow>20

options(width=40, datatable.show.ncols=TRUE)
DT = data.table(a=1:21,b=1:21,c=1:21,d=1:21,e=1:21,f=1:21,g=1:21,h=1:21)
print(DT, trunc.cols=TRUE, class=TRUE)
# Number of columns: 8, of which 3 are not shown: [f <int>, g <int>, h <int>]
# Error in rbind(toprint, matrix(if (quote) old else colnames(toprint),  : 
#   number of columns of matrices must match (see arg 3)

Comment thread R/print.data.table.R Outdated
))
}
if (show.ncols && !isTRUE(trunc.cols) && !any(dim(x)==0L)) {
catf("Number of columns: %d\n", ncol(x))

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.

Maybe use a helper here, similar to trunc_cols_message and dt_width

Comment thread R/print.data.table.R Outdated
cols_to_print = widths < cons_width
not_printed = colnames(toprint)[!cols_to_print]
if (show.ncols) {
n_not_printed = length(not_printed)

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 seems like a near copy of trunc_cols_message, rework it to use it here

Comment thread R/print.data.table.R Outdated
catf("Number of columns: %d, of which %d %s not shown: %s\n",
ncol(x), n_not_printed, ngettext(n_not_printed, "is", "are"),
brackify(paste0(not_printed, classes)))
trunc.cols = FALSE

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.

trunc.cols is now overloaded with multiple tasks. maybe use a separate boolean for this.

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.

Option to print the number of columns

3 participants