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

Internal error discovered in pivot_wider() #1482

Open
bpeterson16 opened this issue Feb 3, 2023 · 2 comments
Open

Internal error discovered in pivot_wider() #1482

bpeterson16 opened this issue Feb 3, 2023 · 2 comments
Labels
bug an unexpected problem or unintended behavior pivoting ♻️ pivot rectangular data to different "shapes"

Comments

@bpeterson16
Copy link

bpeterson16 commented Feb 3, 2023

The function pivot_wider() produces an error:

Error in `rethrow_id_cols_oob()`:
! `i` must be a single string, not an integer vector.
ℹ This is an internal error that was detected in the tidyr package.
  Please report it at <https://github.com/tidyverse/tidyr/issues> with a reprex and the full backtrace.
---
Backtrace:
  1. iris %>% ...
 27. rlang (local) `<fn>`(`<vctrs___>`)
 28. handlers[[1L]](cnd)
 29. tidyr:::rethrow_id_cols_oob(...)
library(tidyverse)
library(dplyr)

pivot <- iris %>%
  pivot_wider(id_cols = 3:5, names_from = Species, values_from = Petal.Width)
@arbgoetz
Copy link

Same issue discovered when using make.unique() on a column containing duplicates

library(tidyverse)
   
   t<-tibble(x = 1:4, y = c("a", "a", "b", "c"), z = c(21, 22, 23, 24))
   w<-pivot_wider(t, id_cols = make.unique(t$y), names_from = x, values_from = y)
#> Error in `rethrow_id_cols_oob()`:
#> ! `i` must be a single string, not a character vector.
#> ℹ This is an internal error that was detected in the tidyr package.
#>   Please report it at <https://github.com/tidyverse/tidyr/issues> with a reprex
#>   (<https://tidyverse.org/help/>) and the full backtrace.
#> Backtrace:
#>      ▆
#>   1. ├─tidyr::pivot_wider(...)
#>   2. ├─tidyr:::pivot_wider.data.frame(...)
#>   3. │ └─tidyr:::build_wider_id_cols_expr(...)
#>   4. │   └─tidyr:::select_wider_id_cols(...)
#>   5. │     ├─rlang::try_fetch(...)
#>   6. │     │ └─base::withCallingHandlers(...)
#>   7. │     └─tidyselect::eval_select(...)
#>   8. │       └─tidyselect:::eval_select_impl(...)
#>   9. │         ├─tidyselect:::with_subscript_errors(...)
#>  10. │         │ └─rlang::try_fetch(...)
#>  11. │         │   └─base::withCallingHandlers(...)
#>  12. │         └─tidyselect:::vars_select_eval(...)
#>  13. │           └─tidyselect:::walk_data_tree(expr, data_mask, context_mask)
#>  14. │             └─tidyselect:::as_indices_sel_impl(...)
#>  15. │               └─tidyselect:::as_indices_impl(...)
#>  16. │                 └─tidyselect:::chr_as_locations(x, vars, call = call, arg = arg)
#>  17. │                   └─vctrs::vec_as_location(...)
#>  18. ├─vctrs (local) `<fn>`()
#>  19. │ └─vctrs:::stop_subscript_oob(...)
#>  20. │   └─vctrs:::stop_subscript(...)
#>  21. │     └─rlang::abort(...)
#>  22. │       └─rlang:::signal_abort(cnd, .file)
#>  23. │         └─base::signalCondition(cnd)
#>  24. ├─rlang (local) `<fn>`(`<vctrs___>`)
#>  25. │ └─handlers[[1L]](cnd)
#>  26. │   └─rlang::cnd_signal(cnd)
#>  27. │     └─rlang:::signal_abort(cnd)
#>  28. │       └─base::signalCondition(cnd)
#>  29. └─rlang (local) `<fn>`(`<vctrs___>`)
#>  30.   └─handlers[[1L]](cnd)
#>  31.     └─tidyr:::rethrow_id_cols_oob(...)
#>  32.       └─tidyr:::check_string(i, .internal = TRUE)
#>  33.         └─tidyr:::stop_input_type(...)
#>  34.           └─rlang::abort(message, ..., call = call, arg = arg)

@hadley
Copy link
Member

hadley commented Nov 1, 2023

This seems to be about selecting columns that don't exist:

library(tidyverse)

df <- tibble(y = c("a", "a", "b", "c"), z = c(21, 22, 23, 24))

pivot_wider(df, id_cols = all_of(c("a", "b", "c")), names_from = y, values_from = z)
#> Error in `rethrow_id_cols_oob()`:
#> ! `i` must be a single string, not a character vector.
#> ℹ This is an internal error that was detected in the tidyr package.
#>   Please report it at <https://github.com/tidyverse/tidyr/issues> with a reprex
#>   (<https://tidyverse.org/help/>) and the full backtrace.

pivot_wider(df, id_cols = 1:2, names_from = y, values_from = z)
#> Error in `rethrow_id_cols_oob()`:
#> ! `i` must be a single string, not an integer vector.
#> ℹ This is an internal error that was detected in the tidyr package.
#>   Please report it at <https://github.com/tidyverse/tidyr/issues> with a reprex
#>   (<https://tidyverse.org/help/>) and the full backtrace.

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

@hadley hadley added bug an unexpected problem or unintended behavior pivoting ♻️ pivot rectangular data to different "shapes" labels Nov 1, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug an unexpected problem or unintended behavior pivoting ♻️ pivot rectangular data to different "shapes"
Projects
None yet
Development

No branches or pull requests

3 participants