Open bpeterson16 opened 1 year ago
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)
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
The function pivot_wider() produces an error: