Conversation
Codecov Report✅ All modified and coverable lines are covered by tests. 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. 🚀 New features to boost your workflow:
|
Generated via commit e697d45 Download link for the artifact containing the test results: ↓ atime-results.zip
|
| cons_width = getOption("width") | ||
| cols_to_print = widths < cons_width | ||
| not_printed = colnames(toprint)[!cols_to_print] | ||
|
|
| 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") |
There was a problem hiding this comment.
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.
ben-schwen
left a comment
There was a problem hiding this comment.
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)| )) | ||
| } | ||
| if (show.ncols && !isTRUE(trunc.cols) && !any(dim(x)==0L)) { | ||
| catf("Number of columns: %d\n", ncol(x)) |
There was a problem hiding this comment.
Maybe use a helper here, similar to trunc_cols_message and dt_width
| cols_to_print = widths < cons_width | ||
| not_printed = colnames(toprint)[!cols_to_print] | ||
| if (show.ncols) { | ||
| n_not_printed = length(not_printed) |
There was a problem hiding this comment.
this seems like a near copy of trunc_cols_message, rework it to use it here
| 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 |
There was a problem hiding this comment.
trunc.cols is now overloaded with multiple tasks. maybe use a separate boolean for this.
| cons_width = getOption("width") | ||
| cols_to_print = widths < cons_width | ||
| not_printed = colnames(toprint)[!cols_to_print] | ||
| if (show.ncols) { |
There was a problem hiding this comment.
The column count seems to be wrong when using show.indices=TRUE
DT = data.table(a=1:3, b=1:3, c=1:3, d=1:3, e=1:3)
setindex(DT, a)
options(width=20, datatable.show.ncols=TRUE)
print(DT, trunc.cols=TRUE, show.indices=TRUE)
# Index: <a>
# Number of columns: 5, of which 4 are not shown: [c <int>, d <int>, e <int>, index:a <int>]
# a b
# <int> <int>
# 1: 1 1
# 2: 2 2
# 3: 3 3| stopf("Valid options for col.names are 'auto', 'top', and 'none'") | ||
| if (length(trunc.cols) != 1L || !is.logical(trunc.cols) || is.na(trunc.cols)) | ||
| stopf("Valid options for trunc.cols are TRUE and FALSE") | ||
| stopifnot(isTRUEorFALSE(class)) |
There was a problem hiding this comment.
| stopifnot(isTRUEorFALSE(class)) | |
| stopifnot(isTRUEorFALSE(show.ncols)) |
see comment below about show.ncols=NA
| cols_to_print = widths < cons_width | ||
| not_printed = colnames(toprint)[!cols_to_print] | ||
| if (show.ncols) { | ||
| trunc_cols_message(not_printed, abbs, class, col.names, ncol=ncol(x)) |
There was a problem hiding this comment.
It might be even as simple to exchange ncol(x) with ncol(toprint)
| if (show.ncols) { | ||
| trunc_cols_message(not_printed, abbs, class, col.names, ncol=ncol(x)) | ||
| show_trunc_message = FALSE | ||
| } |
There was a problem hiding this comment.
| } | |
| } |
wrong indentation
| paste0("<", ixs, ">", collapse = ", ") | ||
| )) | ||
| } | ||
| if (show.ncols && !isTRUE(trunc.cols) && !any(dim(x)==0L)) { |
There was a problem hiding this comment.
can we move this below the any(dim(x)==0L) branch which comes next and drop the !any(dim(x)==0L) guard?

closes #6663.
in this pr I
datatable.show.ncolsoption (default FALSE).trunc.cols=TRUEoutput.hi @tdhock @joshhwuu can you please have a look when you get time.
thanks