From 89591d3230bc924b4f0c2544213bd9d2824f767c Mon Sep 17 00:00:00 2001 From: Michael Chirico Date: Fri, 4 Jul 2025 15:38:17 -0700 Subject: [PATCH] annotate truncated entries with their length --- NEWS.md | 2 ++ R/print.data.table.R | 2 +- inst/tests/tests.Rraw | 6 +++--- 3 files changed, 6 insertions(+), 4 deletions(-) diff --git a/NEWS.md b/NEWS.md index 651ddcf6c9..a17632589a 100644 --- a/NEWS.md +++ b/NEWS.md @@ -101,6 +101,8 @@ + On non-Windows systems, `fread()` now prints the reason why the file couldn't be opened, which could also be due to it being too large to map. + With `verbose=TRUE`, file sizes are now printed using correct binary SI prefixes (the sizes have always been reported as bytes denominated in powers of `2^10`, so e.g. `1024*1024` bytes was reported as `1 MB` where `1 MiB` or `1.05 MB` is correct). +5. The default `format_list_item()` method (and hence `print.data.table()`) annotates truncated list items with their length, [#605](https://github.com/Rdatatable/data.table/issues/605). Thanks Matt Dowle for the original report (2012!) and @MichaelChirico for the fix. + ## data.table [v1.17.0](https://github.com/Rdatatable/data.table/milestone/34) (20 Feb 2025) ### POTENTIALLY BREAKING CHANGES diff --git a/R/print.data.table.R b/R/print.data.table.R index 3e93eb3f81..96e1edfff5 100644 --- a/R/print.data.table.R +++ b/R/print.data.table.R @@ -225,7 +225,7 @@ format_list_item.default = function(x, ...) { if (is.null(x)) # NULL item in a list column "[NULL]" # not '' or 'NULL' to distinguish from those "common" string values in data else if (is.atomic(x) || inherits(x, "formula")) # FR #2591 - format.data.table issue with columns of class "formula" - paste(c(format(head(x, 6L), ...), if (length(x) > 6L) "..."), collapse=",") # fix for #5435 and #37 - format has to be added here... + paste(c(format(head(x, 6L), ...), if (length(x) > 6L) sprintf("...[%d]", length(x))), collapse=",") # fix for #5435, #37, and #605 - format has to be added here... else if (has_format_method(x) && length(formatted<-format(x, ...))==1L) { # the column's class does not have a format method (otherwise it would have been used by format_col and this # format_list_item would not be reached) but this particular list item does have a format method so use it diff --git a/inst/tests/tests.Rraw b/inst/tests/tests.Rraw index 4e71245126..bd07c472fc 100644 --- a/inst/tests/tests.Rraw +++ b/inst/tests/tests.Rraw @@ -348,7 +348,7 @@ xenv = new.env() # to control testing tables() xenv$DT = data.table(a = 1) test(69.5, nrow(tables(env=xenv)), 1L, output="NAME NROW NCOL MB COLS KEY\n1: DT 1 1 0 a [NULL]\nTotal: 0MB") xenv$DT = data.table(A=1:2, B=3:4, C=5:6, D=7:8, E=9:10, F=11:12, G=13:14, H=15:16, key=c("A", "D", "F", "G")) -test(69.6, nrow(tables(env=xenv)), 1L, output="NAME NROW NCOL MB COLS KEY\n1: DT 2 8 0 A,B,C,D,E,F,... A,D,F,G.*Total: 0MB") +test(69.6, nrow(tables(env=xenv)), 1L, output="NAME NROW NCOL MB\\s+COLS\\s+KEY\n1: DT 2 8 0 A,B,C,D,E,F,\\.\\.\\.\\[8\\] A,D,F,G.*Total: 0MB") rm(xenv) test(69.7, tables(order.col='asdf'), error="not a column name of info") @@ -1731,8 +1731,8 @@ test(557, DT[, f(.SD), by=x], error="[.]SD is locked.*reserved for possible futu # Test printing on nested data.table, bug #1803 DT = data.table(x=letters[1:3], y=list(1:10, letters[1:4], data.table(a=1:3,b=4:6))) -test(558, capture.output(print(DT)), - c(" x y", "1: a 1,2,3,4,5,6,...", "2: b a,b,c,d", "3: c ")) +test(558.1, DT, output="\\ba\\s+1,2,3,4,5,6,\\.\\.\\.\\[10\\]") # row 1 +test(558.2, DT, output="\\bc\\s+") # row 3 test(559, setkey(DT,x)["a",y][[1]], 1:10) # y is symbol representing list column, specially detected in dogroups # Test renaming of .N to N