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

pivot_wider_spec() should check if data is a data frame #1510

Open
mgirlich opened this issue Jul 13, 2023 · 0 comments
Open

pivot_wider_spec() should check if data is a data frame #1510

mgirlich opened this issue Jul 13, 2023 · 0 comments
Labels
bug an unexpected problem or unintended behavior

Comments

@mgirlich
Copy link
Contributor

The error message when passing in a lazy_frame() or memdb_frame() are not very helpful:

spec <- tibble::tibble(
  .name = c("x", "y", "z"),
  .value = "val",
  key = c("x", "y", "z")
)

dbplyr::memdb_frame(key = c("x", "y", "z"), val = 1:3) |>
  tidyr::pivot_wider_spec(spec)
#> Error in `data[vec_unique(c(id_cols, names_from_cols, values_from_cols, unused_cols))]`:
#> ! Can't subset columns that don't exist.
#> ✖ Columns `src` and `lazy_query` don't exist.
#> Backtrace:
#>      ▆
#>   1. ├─tidyr::pivot_wider_spec(...)
#>   2. │ ├─...[]
#>   3. │ └─tibble:::`[.tbl_df`(...)
#>   4. │   └─tibble:::vectbl_as_col_location(...)
#>   5. │     ├─tibble:::subclass_col_index_errors(...)
#>   6. │     │ └─base::withCallingHandlers(...)
#>   7. │     └─vctrs::vec_as_location(j, n, names, missing = "error", call = call)
#>   8. └─vctrs (local) `<fn>`()
#>   9.   └─vctrs:::stop_subscript_oob(...)
#>  10.     └─vctrs:::stop_subscript(...)
#>  11.       └─rlang::abort(...)
dbplyr::lazy_frame(key = c("x", "y", "z"), val = 1:3) |>
  tidyr::pivot_wider_spec(spec)
#> Error in `as.data.frame()`:
#> ! Can not coerce <tbl_lazy> to <data.frame>
#> Backtrace:
#>     ▆
#>  1. └─tidyr::pivot_wider_spec(...)
#>  2.   ├─tibble::as_tibble(data)
#>  3.   └─tibble:::as_tibble.default(data)
#>  4.     ├─tibble::as_tibble(...)
#>  5.     ├─base::as.data.frame(value, stringsAsFactors = FALSE)
#>  6.     └─dbplyr:::as.data.frame.tbl_lazy(value, stringsAsFactors = FALSE)
#>  7.       └─cli::cli_abort("Can not coerce {.cls tbl_lazy} to {.cls data.frame}")
#>  8.         └─rlang::abort(...)

Created on 2023-07-13 with reprex v2.0.2

@hadley hadley added the bug an unexpected problem or unintended behavior label 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
Projects
None yet
Development

No branches or pull requests

2 participants