Skip to content

Commit 512f08a

Browse files
committed
Simplify&flatten epi_slide data mask implementation
and add some unrelated comments regarding time value counting details. Since we're not potentially dealing with R6 objects, we can just us `as_data_mask(.x)`. We can also flatten the data mask by installing the `.x`, `.group_key` and `.ref_time_value` in the same way as that pronouns are installed (except keeping their original classes, not converting to pronouns), rather than using another level in the environment chain for the data mask.
1 parent 9db1165 commit 512f08a

File tree

1 file changed

+9
-9
lines changed

1 file changed

+9
-9
lines changed

R/slide.R

+9-9
Original file line numberDiff line numberDiff line change
@@ -299,7 +299,9 @@ epi_slide = function(x, f, ..., before, after, ref_time_values,
299299
o = .data_group$time_value %in% time_values
300300
num_ref_rows = sum(o)
301301

302-
# Count the number of appearances of each reference time value
302+
# Count the number of appearances of each reference time value (these
303+
# appearances should all be real for now, but if we allow ref time values
304+
# outside of .data_group's time values):
303305
counts = .data_group %>%
304306
dplyr::filter(.data$time_value %in% time_values) %>%
305307
dplyr::count(.data$time_value) %>%
@@ -386,14 +388,12 @@ epi_slide = function(x, f, ..., before, after, ref_time_values,
386388
.ref_time_value = min(.x$time_value) + before
387389
.x <- .x[.x$.real,]
388390
.x$.real <- NULL
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)
391+
data_mask = rlang::as_data_mask(.x)
392+
# We'll also install `.x` directly, not as an `rlang_data_pronoun`, so
393+
# that we can, e.g., use more dplyr and epiprocess operations.
394+
data_mask$.x = .x
395+
data_mask$.group_key = .group_key
396+
data_mask$.ref_time_value = .ref_time_value
397397
rlang::eval_tidy(quo, data_mask)
398398
}
399399
new_col = sym(names(rlang::quos_auto_name(quos)))

0 commit comments

Comments
 (0)