Skip to content

Commit d4244e8

Browse files
add format_list_item.data.frame (#6593)
* Closes #6592, nested frames break if any are just 1-column * typo * upd tests * fix typo in test * style, tweaks * refine NEWS * fix link in NEWS * Add as contributor --------- Co-authored-by: Bill Evans <[email protected]> Co-authored-by: Michael Chirico <[email protected]> Co-authored-by: Michael Chirico <[email protected]>
1 parent f05893e commit d4244e8

File tree

5 files changed

+23
-1
lines changed

5 files changed

+23
-1
lines changed

DESCRIPTION

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -99,5 +99,6 @@ Authors@R: c(
9999
person("Elise", "Maigné", role="ctb"),
100100
person("Vincent", "Rocher", role="ctb"),
101101
person("Vijay", "Lulla", role="ctb"),
102-
person("Aljaž", "Sluga", role="ctb")
102+
person("Aljaž", "Sluga", role="ctb"),
103+
person("Bill", "Evans", role="ctb")
103104
)

NAMESPACE

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -201,6 +201,7 @@ S3method(format_col, POSIXct)
201201
S3method(format_col, expression)
202202
export(format_list_item)
203203
S3method(format_list_item, default)
204+
S3method(format_list_item, data.frame)
204205

205206
export(fdroplevels, setdroplevels)
206207
S3method(droplevels, data.table)

NEWS.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -113,6 +113,8 @@ rowwiseDT(
113113
114114
13. `rbindlist(l, use.names=TRUE)` can now handle different encodings for the column names in different entries of `l`, [#5452](https://github.com/Rdatatable/data.table/issues/5452). Thanks to @MEO265 for the report, and Benjamin Schwendinger for the fix.
115115
116+
14. Added a `data.frame` method for `format_list_item()` to fix error printing data.tables with columns containing 1-column data.frames, [#6592](https://github.com/Rdatatable/data.table/issues/6592). Thanks to @r2evans for the bug report and fix.
117+
116118
## NOTES
117119
118120
1. Tests run again when some Suggests packages are missing, [#6411](https://github.com/Rdatatable/data.table/issues/6411). Thanks @aadler for the note and @MichaelChirico for the fix.

R/print.data.table.R

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -247,6 +247,11 @@ format_list_item.default = function(x, ...) {
247247
}
248248
}
249249

250+
# #6592 -- nested 1-column frames breaks printing
251+
format_list_item.data.frame = function(x, ...) {
252+
paste0("<", class1(x), paste_dims(x), ">")
253+
}
254+
250255
# FR #1091 for pretty printing of character
251256
# TODO: maybe instead of doing "this is...", we could do "this ... test"?
252257
# Current implementation may have issues when dealing with strings that have combinations of full-width and half-width characters,

inst/tests/tests.Rraw

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20651,3 +20651,16 @@ test(2298.2, rbindlist(list(y,x), use.names=TRUE), data.table("\u00f6"=c(4,2), "
2065120651
set(y, j="\u00e4", value=NULL)
2065220652
test(2298.3, rbindlist(list(x,y), use.names=TRUE, fill=TRUE), data.table("\u00e4"=c(1,NA), "\u00f6"=c(2,4), "\u00fc"=c(3,5)))
2065320653
test(2298.4, rbindlist(list(y,x), use.names=TRUE, fill=TRUE), data.table("\u00f6"=c(4,2), "\u00fc"=c(5,3), "\u00e4"=c(NA,1)))
20654+
20655+
# #6592: printing nested single-column frames
20656+
test(2299.01, format_list_item(data.frame(a=1)), output="<data.frame[1x1]>")
20657+
test(2299.02, format_list_item(data.frame(a=1)[0,,drop=FALSE]), output="<data.frame[0x1]>")
20658+
test(2299.03, format_list_item(data.frame(a=1)[,0]), output="<data.frame[1x0]>")
20659+
test(2299.04, format_list_item(data.frame(a=1, b=2)[0,,drop=FALSE]), output="<data.frame[0x2]>")
20660+
test(2299.06, format_list_item(data.table(a=1)), output="<data.table[1x1]>")
20661+
test(2299.07, format_list_item(data.table(a=numeric())), output="<data.table[0x1]>")
20662+
test(2299.08, format_list_item(data.table()), output="<data.table[0x0]>")
20663+
test(2299.09, format_list_item(data.table(a=numeric(), b=numeric())), output="<data.table[0x2]>")
20664+
test(2299.10, data.table(a=1), output="a\n1: *1")
20665+
test(2299.11, data.table(a=list(data.frame(b=1))), output="a\n1: <data.frame[1x1]>")
20666+
test(2299.12, data.table(a=list(data.table(b=1))), output="a\n1: <data.table[1x1]>")

0 commit comments

Comments
 (0)