Skip to content

Commit a4c19f7

Browse files
committed
Install .x etc. into data masks in same way pronouns are
1 parent e9580d3 commit a4c19f7

File tree

5 files changed

+25
-15
lines changed

5 files changed

+25
-15
lines changed

R/grouped_epi_archive.R

+12-8
Original file line numberDiff line numberDiff line change
@@ -371,14 +371,18 @@ grouped_epi_archive =
371371

372372
quo = quos[[1]]
373373
f = function(.x, .group_key, .ref_time_value, quo, ...) {
374-
data_parent_env = rlang::as_environment(.x)
375-
data_env = env(data_parent_env,
376-
.x = .x, .group_key = .group_key,
377-
.ref_time_value = .ref_time_value)
378-
# `as_data_mask()` appears to strip off ancestors. We'll need to
379-
# do some more work with `new_data_mask()`:
380-
data_mask = rlang::new_data_mask(data_env, top = data_parent_env)
381-
data_mask$.data <- rlang::as_data_pronoun(.x)
374+
# Convert to environment to standardize between tibble and R6
375+
# based inputs. In both cases, we should get a simple
376+
# environment with the empty environment as its parent.
377+
data_env = rlang::as_environment(.x)
378+
data_mask = rlang::new_data_mask(bottom = data_env, top = data_env)
379+
data_mask$.data <- rlang::as_data_pronoun(data_mask)
380+
# We'll also install `.x` directly, not as an
381+
# `rlang_data_pronoun`, so that we can, e.g., use more dplyr and
382+
# epiprocess operations.
383+
data_mask$.x = .x
384+
data_mask$.group_key = .group_key
385+
data_mask$.ref_time_value = .ref_time_value
382386
rlang::eval_tidy(quo, data_mask)
383387
}
384388
new_col = sym(names(rlang::quos_auto_name(quos)))

R/methods-epi_archive.R

+4-1
Original file line numberDiff line numberDiff line change
@@ -681,7 +681,10 @@ group_by.epi_archive = function(.data, ..., .add=FALSE, .drop=dplyr::group_by_dr
681681
#' reference time value can be accessed via `.ref_time_value`.
682682
#' @param ... Additional arguments to pass to the function or formula specified
683683
#' via `f`. Alternatively, if `f` is missing, then `...` is interpreted as an
684-
#' expression for tidy evaluation. See details of [`epi_slide`].
684+
#' expression for tidy evaluation; in addition to referring to columns
685+
#' directly by name, the expression has access to a `.data` and `.env`
686+
#' pronouns as in `dplyr` verbs, and can also refer to the `.group_key` and
687+
#' `.ref_time_value`. See details of [`epi_slide`].
685688
#' @param before How far `before` each `ref_time_value` should the sliding
686689
#' window extend? If provided, should be a single, non-NA,
687690
#' [integer-compatible][vctrs::vec_cast] number of time steps. This window

man/epi_slide.Rd

+2-2
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

man/epix_slide.Rd

+6-3
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

man/reexports.Rd

+1-1
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)