Skip to content

Commit 307fb6e

Browse files
committed
use custom data mask rather than quo env to match epix_slide tidyeval implmentation
1 parent 9ccfe91 commit 307fb6e

File tree

3 files changed

+14
-7
lines changed

3 files changed

+14
-7
lines changed

NAMESPACE

-1
Original file line numberDiff line numberDiff line change
@@ -112,7 +112,6 @@ importFrom(rlang,is_string)
112112
importFrom(rlang,missing_arg)
113113
importFrom(rlang,new_function)
114114
importFrom(rlang,quo_is_missing)
115-
importFrom(rlang,quo_set_env)
116115
importFrom(rlang,sym)
117116
importFrom(rlang,syms)
118117
importFrom(stats,cor)

R/slide.R

+10-3
Original file line numberDiff line numberDiff line change
@@ -120,7 +120,7 @@
120120
#'
121121
#' @importFrom lubridate days weeks
122122
#' @importFrom dplyr bind_rows group_vars filter select
123-
#' @importFrom rlang .data .env !! enquo enquos sym quo_set_env env
123+
#' @importFrom rlang .data .env !! enquo enquos sym env
124124
#' @export
125125
#' @examples
126126
#' # slide a 7-day trailing average formula on cases
@@ -386,8 +386,15 @@ epi_slide = function(x, f, ..., before, after, ref_time_values,
386386
.ref_time_value = min(.x$time_value) + before
387387
.x <- .x[.x$.real,]
388388
.x$.real <- NULL
389-
quo = quo_set_env(quo, env())
390-
rlang::eval_tidy(quo, .x)
389+
data_parent_env = rlang::as_environment(.x)
390+
data_env = env(data_parent_env,
391+
.x = .x, .group_key = .group_key,
392+
.ref_time_value = .ref_time_value)
393+
# `as_data_mask()` appears to strip off ancestors. We'll need to
394+
# do some more work with `new_data_mask()`:
395+
data_mask = rlang::new_data_mask(data_env, top = data_parent_env)
396+
data_mask$.data <- rlang::as_data_pronoun(.x)
397+
rlang::eval_tidy(quo, data_mask)
391398
}
392399
new_col = sym(names(rlang::quos_auto_name(quos)))
393400

tests/testthat/test-epi_slide.R

+4-3
Original file line numberDiff line numberDiff line change
@@ -447,11 +447,12 @@ test_that("epi_slide computation via dots can use ref_time_value and group", {
447447

448448
expect_identical(result1, expected_output)
449449

450-
result2 <- small_x %>%
450+
# `.{x,group_key,ref_time_value}` should be inaccessible from `.data` and
451+
# `.env`.
452+
expect_error(small_x %>%
451453
epi_slide(before = 50,
452454
slide_value = .env$.ref_time_value)
453-
454-
expect_identical(result2, expected_output)
455+
)
455456

456457
# group_key
457458
# Use group_key column

0 commit comments

Comments
 (0)