Skip to content

Improve error message for incompatible ptype unnest() #1477

Closed

Description

@mgirlich
library(tidyr)

tibble(x = 1, data = list(1, 2:3), data2 = list("a", 2:3)) %>% 
  unnest(c(data, data2), ptype = list(data = integer(), data2 = character()))
#> Error in `list_unchop()`:
#> ! Can't convert `x[[2]]` <integer> to <character>.

#> Backtrace:
#>      ▆
#>   1. ├─... %>% ...
#>   2. ├─tidyr::unnest(...)
#>   3. ├─tidyr:::unnest.data.frame(...)
#>   4. │ └─tidyr::unchop(...)
#>   5. │   └─tidyr:::df_unchop(...)
#>   6. │     └─vctrs::list_unchop(col, ptype = col_ptype)
#>   7. └─vctrs (local) `<fn>`()
#>   8.   └─vctrs::vec_default_cast(...)
#>   9.     ├─base::withRestarts(...)
#>  10.     │ └─base (local) withOneRestart(expr, restarts[[1L]])
#>  11.     │   └─base (local) doWithOneRestart(return(expr), restart)
#>  12.     └─vctrs::stop_incompatible_cast(...)
#>  13.       └─vctrs::stop_incompatible_type(...)
#>  14.         └─vctrs:::stop_incompatible(...)
#>  15.           └─vctrs:::stop_vctrs(...)
#>  16.             └─rlang::abort(message, class = c(class, "vctrs_error"), ..., call = vctrs_error_call(call))

Created on 2023-01-25 with reprex v2.0.2

Two things could be improved:

  1. The error should mention unnest() instead of list_unchop()
  2. Would be nice to mention data2[[2]] instead of x[[2]]

Activity

  1. added
    featurea feature request or enhancement
    nesting 🐦nesting, chopping, and packing
    on Nov 1, 2023
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

    featurea feature request or enhancementnesting 🐦nesting, chopping, and packing

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions