-
Notifications
You must be signed in to change notification settings - Fork 1k
bug fix: truncate wide columns in print.data.table #7788
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: master
Are you sure you want to change the base?
Changes from all commits
b1412c1
460da17
74f6b1a
4fb6707
72b6b72
6a1d3a8
741974b
aa8c344
470053d
b832b60
0830289
26493ff
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change | ||||||
|---|---|---|---|---|---|---|---|---|
|
|
@@ -21660,3 +21660,12 @@ test(2374.08, key(DT[, .(a, a)]), NULL) | |||||||
| test(2374.09, key(subset(DT, select=c(a, a))), NULL) | ||||||||
| DT = data.table(a=1:2, a.1=3:4, val=10:11) | ||||||||
| test(2374.10, key(DT[, .(a.1, sum(val)), keyby=.(a, a)]), NULL) | ||||||||
|
|
||||||||
|
venom1204 marked this conversation as resolved.
|
||||||||
| # print.data.table truncates long character columns based on width | ||||||||
| test(2375.1, capture.output(print(data.table(x="1234567890"))), output="1234...", options=list(width=10, datatable.prettyprint.char=NULL)) | ||||||||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I think capture.output should be removed from these, but keep Also please add this test with Inf
Suggested change
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. hi do i need to cover the issue #7715 in this pr or make a seperate one for it ?
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. please make it separate |
||||||||
| test(2375.11, print(data.table(x="1234567890")), output="1234567890", options=list(width=10, datatable.prettyprint.char=Inf)) | ||||||||
| test(2375.2, capture.output(print(data.table(L=list(1:20)))), output="1,2,3,4,...", options=list(width=15, datatable.prettyprint.char=NULL)) | ||||||||
| test(2375.3, capture.output(print(data.table(x=c("short", "abcdefghijklmnopqrstuvwxyz")))), output="abcdefghijklmn...", options=list(width=20, datatable.prettyprint.char=NULL)) | ||||||||
| test(2375.4, capture.output(print(data.table(x="abcdefghijklmnopqrstuvwxyz"))), output="abcdefghijklmnopqrstuvwxyz", options=list(width=200, datatable.prettyprint.char=NULL)) | ||||||||
| test(2375.5, capture.output(print(data.table(id=1L, score=99.1, txt="abcdefghijklmnopqrstuvwxyz"))), output="abcdefghijklmn...", options=list(width=20, datatable.prettyprint.char=NULL)) | ||||||||
| test(2375.6, tail(capture.output(print(data.table(x=rep("ABCDEFGHIJKLMNOPQRSTUVWXYZ", 1000000)), topn=1)), 1), output="1000000: ABCDEFGHIJKLM...", options=list(width=25, datatable.prettyprint.char=NULL)) | ||||||||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -30,17 +30,18 @@ | |
| timezone=FALSE, \dots) | ||
|
|
||
| format_col(x, \dots) | ||
| \method{format_col}{default}(x, \dots) | ||
| \method{format_col}{default}(x, \dots, trunc.char = getOption("datatable.prettyprint.char")) | ||
| \method{format_col}{POSIXct}(x, \dots, timezone=FALSE) | ||
| \method{format_col}{expression}(x, \dots) | ||
| \method{format_col}{expression}(x, \dots, trunc.char = getOption("datatable.prettyprint.char")) | ||
|
|
||
| format_list_item(x, \dots) | ||
| \method{format_list_item}{default}(x, \dots) | ||
| \method{format_list_item}{default}(x, \dots, trunc.char = getOption("datatable.prettyprint.char")) | ||
| } | ||
| \arguments{ | ||
| \item{x}{ A \code{data.table}. } | ||
| \item{topn}{ The number of rows to be printed from the beginning and end of tables with more than \code{nrows} rows. } | ||
| \item{nrows}{ The number of rows which will be printed before truncation is enforced. } | ||
| \item{trunc.char}{The number of characters at which character columns and list-column summaries are truncated. If \code{NULL} (the default), it is dynamically calculated based on \code{getOption("width")}.} | ||
| \item{class}{ If \code{TRUE}, the resulting output will include above each column its storage class (or a self-evident abbreviation thereof). When combined with \code{col.names="auto"} and tables >20 rows, classes will also appear at the bottom.} | ||
| \item{row.names}{ If \code{TRUE}, row indices will be printed alongside \code{x}. } | ||
| \item{col.names}{ One of three flavours for controlling the display of column names in output. \code{"auto"} includes column names above the data, as well as below the table if \code{nrow(x) > 20} (when \code{class=TRUE}, column classes will also appear at the bottom). \code{"top"} excludes this lower register when applicable, and \code{"none"} suppresses column names altogether (as well as column classes if \code{class = TRUE}. } | ||
|
|
@@ -134,5 +135,13 @@ | |
| iris_agg = iris[ , .(reg = list(lm(Sepal.Length ~ Petal.Length))), by = Species] | ||
| format_list_item.lm = function(x, ...) sprintf('<lm:\%s>', format(x$call$formula)) | ||
| print(iris_agg) | ||
|
|
||
| # Truncation based on console width | ||
| old = options(width = 25, datatable.prettyprint.char = NULL) | ||
| 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) | ||
|
Comment on lines
+141
to
+145
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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?
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. here is what i got as a result
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. excellent |
||
| } | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.