Skip to content
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

add format_list_item.data.frame #6593

Merged
merged 9 commits into from
Dec 3, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion DESCRIPTION
Original file line number Diff line number Diff line change
Expand Up @@ -99,5 +99,6 @@ Authors@R: c(
person("Elise", "Maigné", role="ctb"),
person("Vincent", "Rocher", role="ctb"),
person("Vijay", "Lulla", role="ctb"),
person("Aljaž", "Sluga", role="ctb")
person("Aljaž", "Sluga", role="ctb"),
person("Bill", "Evans", role="ctb")
)
1 change: 1 addition & 0 deletions NAMESPACE
Original file line number Diff line number Diff line change
Expand Up @@ -201,6 +201,7 @@ S3method(format_col, POSIXct)
S3method(format_col, expression)
export(format_list_item)
S3method(format_list_item, default)
S3method(format_list_item, data.frame)

export(fdroplevels, setdroplevels)
S3method(droplevels, data.table)
2 changes: 2 additions & 0 deletions NEWS.md
Original file line number Diff line number Diff line change
Expand Up @@ -113,6 +113,8 @@ rowwiseDT(

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.

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.

## NOTES

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.
Expand Down
5 changes: 5 additions & 0 deletions R/print.data.table.R
Original file line number Diff line number Diff line change
Expand Up @@ -247,6 +247,11 @@ format_list_item.default = function(x, ...) {
}
}

# #6592 -- nested 1-column frames breaks printing
format_list_item.data.frame = function(x, ...) {
paste0("<", class1(x), paste_dims(x), ">")
}

# FR #1091 for pretty printing of character
# TODO: maybe instead of doing "this is...", we could do "this ... test"?
# Current implementation may have issues when dealing with strings that have combinations of full-width and half-width characters,
Expand Down
13 changes: 13 additions & 0 deletions inst/tests/tests.Rraw
Original file line number Diff line number Diff line change
Expand Up @@ -20651,3 +20651,16 @@ test(2298.2, rbindlist(list(y,x), use.names=TRUE), data.table("\u00f6"=c(4,2), "
set(y, j="\u00e4", value=NULL)
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)))
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)))

# #6592: printing nested single-column frames
test(2299.01, format_list_item(data.frame(a=1)), output="<data.frame[1x1]>")
test(2299.02, format_list_item(data.frame(a=1)[0,,drop=FALSE]), output="<data.frame[0x1]>")
test(2299.03, format_list_item(data.frame(a=1)[,0]), output="<data.frame[1x0]>")
test(2299.04, format_list_item(data.frame(a=1, b=2)[0,,drop=FALSE]), output="<data.frame[0x2]>")
test(2299.06, format_list_item(data.table(a=1)), output="<data.table[1x1]>")
test(2299.07, format_list_item(data.table(a=numeric())), output="<data.table[0x1]>")
test(2299.08, format_list_item(data.table()), output="<data.table[0x0]>")
test(2299.09, format_list_item(data.table(a=numeric(), b=numeric())), output="<data.table[0x2]>")
test(2299.10, data.table(a=1), output="a\n1: *1")
test(2299.11, data.table(a=list(data.frame(b=1))), output="a\n1: <data.frame[1x1]>")
test(2299.12, data.table(a=list(data.table(b=1))), output="a\n1: <data.table[1x1]>")
Loading