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

lead / lag within function with .data$ #441

Closed
shriv opened this issue Aug 13, 2023 · 3 comments · Fixed by #442
Closed

lead / lag within function with .data$ #441

shriv opened this issue Aug 13, 2023 · 3 comments · Fixed by #442
Labels
bug an unexpected problem or unintended behavior

Comments

@shriv
Copy link

shriv commented Aug 13, 2023

I'm using dtplyr within an R package of data transformations. I'm using dtplyr_1.3.1 and dplyr_1.1.1 on an M1 mac.

I rely heavily on lead() and lag(). However, I find that neither lead() nor lag() can be used with columns referenced with .data$<column_name>. test_fn_working() has no issues but if you run test_fun_not_working() from the reprex, you get the following error.

Is there a workaround to use .data$<column_name> within lead() and lag() functions?

Error:
! Can't subset `.data` outside of a data mask context.
Run `rlang::last_trace()` to see where the error occurred.
library(dplyr)
library(dtplyr)

test_fn_working <- function(){
  
  dplyr::tibble(
    a = seq(1, 10, 1)
  ) |> 
    dtplyr::lazy_dt() |> 
    dplyr::mutate(
      b = lead(a)
    )
}

test_fn_not_working <- function(){
  
  dplyr::tibble(
    a = seq(1, 10, 1)
  ) |> 
    dtplyr::lazy_dt() |> 
    dplyr::mutate(
      b = lead(.data$a)
    )
}
@markfairbanks markfairbanks added the bug an unexpected problem or unintended behavior label Aug 14, 2023
@shriv
Copy link
Author

shriv commented Aug 21, 2023

Hi @markfairbanks and @eutwt - thanks so much for merging the PR for this bug so quickly! :-) Much appreciated..! Do you know when you might release a dev version with this fix? Thanks!

@markfairbanks
Copy link
Collaborator

You're welcome, thanks for letting us know about the issue 😄

You can install the dev version that contains the fix with this command:

devtools::install_github("tidyverse/dtplyr")

As for the next CRAN release, I would guess it will be in a few months.

@shriv
Copy link
Author

shriv commented Aug 22, 2023

Fab! I'll install the github dev version to get the fix :-)

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

Successfully merging a pull request may close this issue.

2 participants