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)
)
}
I'm using
dtplyrwithin an R package of data transformations. I'm usingdtplyr_1.3.1anddplyr_1.1.1on an M1 mac.I rely heavily on
lead()andlag(). However, I find that neitherlead()norlag()can be used with columns referenced with.data$<column_name>.test_fn_working()has no issues but if you runtest_fun_not_working()from the reprex, you get the following error.Is there a workaround to use
.data$<column_name>withinlead()andlag()functions?