Skip to content

tibbles nested inside tibbles cause errors in repr_text #154

Description

@michaelquinn32

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:

else format(col)

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" ...

Activity

  1. MichaelChirico commented on Jul 15, 2024

    @MichaelChirico
    Contributor

    I think this is closed by #166 (just not marked as such by the PR)

  2. flying-sheep commented on Aug 6, 2024

    @flying-sheep
    Member

    yup, printing this works fine now!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions