repr
repr copied to clipboard
tibbles nested inside tibbles cause errors in repr_text
Hi team!
Here's a reprex.
library(tibble)
library(repr)
tbl_obj <- tibble::tibble(
col1 = tibble::tibble(
inner_col1 = 1
)
)
repr::repr_text(tbl_obj)
Error in vapply(part, function(col) {: values must be length 1,
but FUN(X[[1]]) result is length 4
Traceback:
1. repr::repr_text(tbl_obj)
2. repr_text.data.frame(tbl_obj)
3. ellip_limit_arr(obj, rows, cols)
4. arr_parts_format(parts)
5. structure(lapply(parts, arr_part_format), omit = attr(parts,
. "omit"))
6. lapply(parts, arr_part_format)
7. FUN(X[[i]], ...)
8. vapply(part, function(col) {
. if (is.matrix(col))
. apply(apply(col, 2L, format), 1L, paste, collapse = ", ")
. else format(col)
. }, character(nrow(part)))
The error is being thrown by this line of code: https://github.com/IRkernel/repr/blob/f4780e5ab58054d69ef77a0f61b239bebd106de5/R/repr_matrix_df.r#L68
IIUC, this is due to the fact that format(tbl()) can return a character vector that's longer than the number of rows in the data frame. For example:
str(format(tibble::tibble(a = 1)))
#> chr [1:4] "\033[38;5;246m# A tibble: 1 × 1\033[39m" " a" ...
I think this is closed by #166 (just not marked as such by the PR)
yup, printing this works fine now!