@@ -998,13 +998,15 @@ dplyr_col_modify.col_modify_recorder_df <- function(data, cols) {
998
998
# '
999
999
# ' @details
1000
1000
# '
1001
- # ' By default, using the `version` column is disabled as it's easy to
1002
- # ' get unexpected results. See if either [`epix_as_of`] or [`epix_slide`]
1003
- # ' works as an alternative. If they don't cover your use case, then you can
1004
- # ' set `.format_aware = TRUE` to enable usage of the `version` column, but be
1005
- # ' careful to:
1006
- # ' * Factor in that `.data$DT` may be using a "compact" format based on diffing
1007
- # ' consecutive versions; see details of [`as_epi_archive`]
1001
+ # ' By default, using the `version` column or measurement columns is disabled as
1002
+ # ' it's easy to get unexpected results. See if either [`epix_as_of`] or
1003
+ # ' [`epix_slide`] works as an alternative. If they don't cover your use case,
1004
+ # ' then you can set `.format_aware = TRUE` to enable usage of these columns, but
1005
+ # ' be careful to:
1006
+ # ' * Factor in that `.data$DT` may have been converted into a compact format
1007
+ # ' based on diffing consecutive versions, and the last version of each
1008
+ # ' observation in `.data$DT` will always be carried forward to future
1009
+ # ' `version`s`; see details of [`as_epi_archive`].
1008
1010
# ' * Set `clobberable_versions_start` and `versions_end` of the result
1009
1011
# ' appropriately after the `filter` call. They will be initialized with the
1010
1012
# ' same values as in `.data`.
@@ -1024,13 +1026,14 @@ dplyr_col_modify.col_modify_recorder_df <- function(data, cols) {
1024
1026
# ' archive_cases_dv_subset %>%
1025
1027
# ' filter(as.POSIXlt(time_value)$wday == 6L)
1026
1028
# '
1027
- # ' # Filtering involving versions requires extra care. See epix_as_of and
1028
- # ' # epix_slide instead for some common operations. One semi-common operation
1029
- # ' # that ends up being fairly simple is treating observations as finalized
1030
- # ' # after some amount of time, and ignoring any revisions that were made after
1031
- # ' # that point:
1029
+ # ' # Filtering involving the `version` column or measurement columns requires
1030
+ # ' # extra care. See epix_as_of and epix_slide instead for some common
1031
+ # ' # operations. One semi-common operation that ends up being fairly simple is
1032
+ # ' # treating observations as finalized after some amount of time, and ignoring
1033
+ # ' # any revisions that were made after that point:
1032
1034
# ' archive_cases_dv_subset %>%
1033
- # ' filter(version <= time_value + as.difftime(60, units = "days"),
1035
+ # ' filter(
1036
+ # ' version <= time_value + as.difftime(60, units = "days"),
1034
1037
# ' .format_aware = TRUE
1035
1038
# ' )
1036
1039
# '
@@ -1041,25 +1044,37 @@ filter.epi_archive <- function(.data, ..., .by = NULL, .format_aware = FALSE) {
1041
1044
out_tbl <- in_tbl %> %
1042
1045
filter(... , .by = .by )
1043
1046
} else {
1047
+ measurement_colnames <- setdiff(names(.data $ DT ), key_colnames(.data ))
1048
+ forbidden_colnames <- c(" version" , measurement_colnames )
1044
1049
out_tbl <- in_tbl %> %
1045
1050
filter(
1046
1051
# Add our own fake filter arg to the user's ..., to update the data mask
1047
1052
# to prevent `version` column usage.
1048
1053
{
1049
1054
# We should be evaluating inside the data mask. To disable both
1050
- # `version` and `.data$version`, we need to go to the data mask's
1051
- # ------
1055
+ # `version` and `.data$version` etc., we need to go to the ancestor
1056
+ # environment containing the data mask's column bindings. This is
1057
+ # likely just the parent env, but search to make sure, in a way akin
1058
+ # to `<<-`:
1052
1059
e <- environment()
1053
1060
while (! identical(e , globalenv()) && ! identical(e , emptyenv())) {
1054
1061
if (" version" %in% names(e )) {
1055
- # "version" is expected to be an active binding, and directly
1056
- # assigning over it has issues; explicitly `rm` first.
1057
- rm(list = " version" , envir = e )
1062
+ # This is where the column bindings are. Replace the forbidden ones.
1063
+ # They are expected to be active bindings, so directly
1064
+ # assigning has issues; `rm` first.
1065
+ rm(list = forbidden_colnames , envir = e )
1058
1066
delayedAssign(" version" , cli :: cli_abort(c(
1059
- " Using `version` in `filter` may produce unexpected results." ,
1067
+ " Using `version` in `filter.epi_archive ` may produce unexpected results." ,
1060
1068
" >" = " See if `epix_as_of` or `epix_slide` would work instead." ,
1061
1069
" >" = " If not, see `?filter.epi_archive` details for how to proceed."
1062
1070
)), assign.env = e )
1071
+ for (measurement_colname in measurement_colnames ) {
1072
+ delayedAssign(measurement_colname , cli :: cli_abort(c(
1073
+ " Using `{format_varname(measurement_colname)}`
1074
+ in `filter.epi_archive` may produce unexpected results." ,
1075
+ " >" = " See `?filter.epi_archive` details for how to proceed."
1076
+ )), assign.env = e )
1077
+ }
1063
1078
break
1064
1079
}
1065
1080
e <- parent.env(e )
0 commit comments