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

"! Can't extract an environment from a call." when using dplyr::desc(). #1548

Open
avhz opened this issue Oct 23, 2024 · 0 comments
Open

"! Can't extract an environment from a call." when using dplyr::desc(). #1548

avhz opened this issue Oct 23, 2024 · 0 comments

Comments

@avhz
Copy link

avhz commented Oct 23, 2024

Not sure if this is a bug or not, but I have run into the following issue.

My actual workflow is with company data but I have managed to reproduce it with a pipeline that is close enough:

This works:

lf <- dbplyr::lazy_frame(
    a = TRUE, b = 1, c = 2, d = "z", 
    con = dbplyr::simulate_hana()
)
  
lf |> 
    dplyr::filter(.data$a == TRUE) |>
    dplyr::group_by(.data$b) |>
    dplyr::mutate(e = .data$b + .data$c) |>
    dbplyr::window_order(desc(.data$e)) |>      ## Note this line.
    dplyr::distinct(.data$d, .keep_all = TRUE)

Returns:

<SQL>
SELECT `a`, `b`, `c`, `d`, `e`
FROM (
  SELECT
    `q01`.*,
    ROW_NUMBER() OVER (PARTITION BY `b`, `d` ORDER BY `e` DESC) AS `col01`
  FROM (
    SELECT `df`.*, `b` + `c` AS `e`
    FROM `df`
    WHERE (`a` = TRUE)
  ) AS `q01`
) AS `q01`
WHERE (`col01` = 1)

This does not work:

lf <- dbplyr::lazy_frame(
    a = TRUE, b = 1, c = 2, d = "z", 
    con = dbplyr::simulate_hana()
)
  
lf |> 
    dplyr::filter(.data$a == TRUE) |>
    dplyr::group_by(.data$b) |>
    dplyr::mutate(e = .data$b + .data$c) |>
    dbplyr::window_order(dplyr::desc(.data$e)) |>  ## Note: I have now fully-qualified the desc() call.
    dplyr::distinct(.data$d, .keep_all = TRUE)

Returns:

Error in `get_env()` at dbplyr/R/translate-sql.R:166:3:
! Can't extract an environment from a call.
Run `rlang::last_trace()` to see where the error occurred.
@avhz avhz changed the title "! Can't extract an environment from a call." when using ´dplyr::desc()´. "! Can't extract an environment from a call." when using dplyr::desc(). Oct 23, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant