Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Improve error message for incompatible ptype unnest() #1477

Open
mgirlich opened this issue Jan 25, 2023 · 0 comments · May be fixed by #1478
Open

Improve error message for incompatible ptype unnest() #1477

mgirlich opened this issue Jan 25, 2023 · 0 comments · May be fixed by #1478
Labels
feature a feature request or enhancement nesting 🐦 nesting, chopping, and packing

Comments

@mgirlich
Copy link
Contributor

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]]
@mgirlich mgirlich linked a pull request Jan 25, 2023 that will close this issue
@hadley hadley added feature a feature request or enhancement nesting 🐦 nesting, chopping, and packing labels Nov 1, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
feature a feature request or enhancement nesting 🐦 nesting, chopping, and packing
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants