Skip to content

Commit 57d72b5

Browse files
simplify format_col.default, allowing e.g. vctrs_list_of columns to print well
1 parent a36caac commit 57d72b5

File tree

3 files changed

+11
-3
lines changed

3 files changed

+11
-3
lines changed

NEWS.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -117,6 +117,8 @@ rowwiseDT(
117117
118118
15. The auto-printing suppression in `knitr` documents is now done by implementing a method for `knit_print` instead of looking up the call stack, [#6589](https://github.com/Rdatatable/data.table/pull/6589). Thanks to @jangorecki for the report [#6509](https://github.com/Rdatatable/data.table/issues/6509) and @aitap for the fix.
119119
120+
16. A data.table with a column of class `vctrs_list_of` (from package {vctrs}) prints as expected, [#5948](https://github.com/Rdatatable/data.table/issues/5948). Before, they could be printed messily, e.g. printing every entry in a nested data.frame. Thanks @jesse-smith for the report, @DavisVaughan and @r2evans for contributing, and @MichaelChirico for the PR.
121+
120122
## NOTES
121123
122124
1. There is a new vignette on joins! See `vignette("datatable-joins")`. Thanks to Angel Feliz for authoring it! Feedback welcome. This vignette has been highly requested since 2017: [#2181](https://github.com/Rdatatable/data.table/issues/2181).

R/print.data.table.R

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -193,8 +193,6 @@ has_format_method = function(x) {
193193
format_col.default = function(x, ...) {
194194
if (!is.null(dim(x)))
195195
"<multi-column>"
196-
else if (has_format_method(x) && length(formatted<-format(x, ...))==length(x))
197-
formatted #PR5224 motivated by package sf where column class is c("sfc_MULTIPOLYGON","sfc") and sf:::format.sfc exists
198196
else if (is.list(x))
199197
vapply_1c(x, format_list_item, ...)
200198
else
@@ -236,6 +234,8 @@ format_list_item.data.frame = function(x, ...) {
236234
paste0("<", class1(x), paste_dims(x), ">")
237235
}
238236

237+
# format_list_item.vctrs_list_of = function(, .)
238+
239239
# FR #1091 for pretty printing of character
240240
# TODO: maybe instead of doing "this is...", we could do "this ... test"?
241241
# Current implementation may have issues when dealing with strings that have combinations of full-width and half-width characters,

inst/tests/other.Rraw

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
pkgs = c("ggplot2", "hexbin", "plyr", "dplyr", "caret", "zoo", "xts", "gdata", "nlme", "bit64", "knitr", "parallel", "sf", "nanotime", "R.utils", "yaml")
1+
pkgs = c("bit64", "caret", "dplyr", "gdata", "ggplot2", "hexbin", "knitr", "nanotime", "nlme", "parallel", "plyr", "R.utils", "sf", "vctrs", "xts", "yaml", "zoo")
22
# First expression of this file must be as above: .gitlab-ci.yml uses parse(,n=1L) to read one expression from this file and installs pkgs.
33
# So that these dependencies of other.Rraw are maintained in a single place.
44
# TEST_DATA_TABLE_WITH_OTHER_PACKAGES is off by default so this other.Rraw doesn't run on CRAN. It is run by GLCI, locally in dev, and by
@@ -773,3 +773,9 @@ if (loaded[["nanotime"]]) {
773773
res <- tables(env=.e)
774774
test(32, res[, .(NAME,NROW,NCOL,MB)], data.table(NAME="DT",NROW=20000000L,NCOL=15L,MB=2288.0))
775775
rm(.e, res)
776+
777+
if (loaded[["vctrs"]]) {
778+
# vctrs::list_of() columns are treated the same as other list() columns
779+
DT = data.table(a = 1, b = list_of(mtcars))
780+
test(33, DT, output="<vctrs_list_of>.*<data\\.frame\\[32x11\\]>")
781+
}

0 commit comments

Comments
 (0)