Open r2evans opened 3 days ago
If we change the current internal function to the following, it works:
format_list_item2 <- function(x, ...) {
if (is.null(x))
"[NULL]"
else if (is.atomic(x) || inherits(x, "formula"))
paste(c(format(head(x, 6L), ...), if (length(x) > 6L) "..."),
collapse = ",")
else if (!inherits(x, "data.frame") && has_format_method(x) && length(formatted <- format(x, ...)) == 1L) {
formatted
}
else {
paste0("<", class(x)[1L], paste_dims(x), ">")
}
}
vapply_1c(x, format_list_item2, ...)
# [1] "<data.frame[1x1]>" "<data.frame[1x1]>" "<data.frame[1x1]>"
Is that simple enough? I'm happy to submit a PR to that effect. (I'd change the original format_list_item.default
, not add the above renamed function. The only change is the addition of !inherits(..)
.)
I think registering format_list_item.data.frame
is the right approach here.
(This may be related to https://github.com/Rdatatable/data.table/issues/5948, since nested frames is a common link.)
When debugging,
Where it is assumed that all return values from
vapply_1c
are expected to be strings.Note that this does not fail when the nested frames are more than one column, since
format_list_item.default
perhaps-naively useslength(format(..)) == 1
.I don't know if it makes sense to define
format_list_item.data.frame
as well to preclude this, or if there are better methods:This test was done with
data.table_1.16.2
, but it also fails withdata.table_1.15.2
, so it's not a recent breakage.sessionInfo()