Skip to content

Commit aa40093

Browse files
annotate truncated entries with their length (#7129)
Co-authored-by: Benjamin Schwendinger <[email protected]>
1 parent 475599a commit aa40093

File tree

3 files changed

+5
-4
lines changed

3 files changed

+5
-4
lines changed

NEWS.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -101,6 +101,7 @@
101101
+ 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.
102102
+ 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).
103103
104+
4. 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.
104105
105106
# data.table [v1.17.8](https://github.com/Rdatatable/data.table/milestone/41) (6 July 2025)
106107

R/print.data.table.R

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -227,7 +227,7 @@ format_list_item.default = function(x, ...) {
227227
if (is.null(x)) # NULL item in a list column
228228
"[NULL]" # not '' or 'NULL' to distinguish from those "common" string values in data
229229
else if (is.atomic(x) || inherits(x, "formula")) # FR #2591 - format.data.table issue with columns of class "formula"
230-
paste(c(format(head(x, 6L), ...), if (length(x) > 6L) "..."), collapse=",") # fix for #5435 and #37 - format has to be added here...
230+
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...
231231
else if (has_format_method(x) && length(formatted<-format(x, ...))==1L) {
232232
# the column's class does not have a format method (otherwise it would have been used by format_col and this
233233
# format_list_item would not be reached) but this particular list item does have a format method so use it

inst/tests/tests.Rraw

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -349,7 +349,7 @@ xenv = new.env() # to control testing tables()
349349
xenv$DT = data.table(a = 1)
350350
test(69.5, nrow(tables(env=xenv)), 1L, output="NAME NROW NCOL MB COLS KEY\n1: DT 1 1 0 a [NULL]\nTotal: 0MB")
351351
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"))
352-
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")
352+
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")
353353
rm(xenv)
354354
test(69.7, tables(order.col='asdf'), error="not a column name of info")
355355

@@ -1732,8 +1732,8 @@ test(557, DT[, f(.SD), by=x], error="[.]SD is locked.*reserved for possible futu
17321732

17331733
# Test printing on nested data.table, bug #1803
17341734
DT = data.table(x=letters[1:3], y=list(1:10, letters[1:4], data.table(a=1:3,b=4:6)))
1735-
test(558, capture.output(print(DT)),
1736-
c(" x y", "1: a 1,2,3,4,5,6,...", "2: b a,b,c,d", "3: c <data.table[3x2]>"))
1735+
test(558.1, DT, output="\\ba\\s+1,2,3,4,5,6,\\.\\.\\.\\[10\\]") # row 1
1736+
test(558.2, DT, output="\\bc\\s+<data\\.table\\[3x2\\]>") # row 3
17371737
test(559, setkey(DT,x)["a",y][[1]], 1:10) # y is symbol representing list column, specially detected in dogroups
17381738

17391739
# Test renaming of .N to N

0 commit comments

Comments
 (0)