54
54
# ' @export
55
55
# ' @importFrom cli cli_inform cli_abort cli_li
56
56
# ' @importFrom rlang list2 syms
57
- # ' @importFrom dplyr mutate group_by arrange filter if_any all_of across pull
57
+ # ' @importFrom dplyr mutate group_by arrange filter if_any all_of across pull pick
58
58
# ' everything ungroup summarize if_else %>%
59
59
revision_summary <- function (epi_arch ,
60
60
... ,
@@ -66,10 +66,10 @@ revision_summary <- function(epi_arch,
66
66
rel_spread_threshold = 0.1 ,
67
67
abs_spread_threshold = NULL ,
68
68
compactify_tol = .Machine $ double.eps ^ 0.5 ) {
69
- arg <- enquos( ... )
69
+ arg <- names(eval_select( rlang :: expr(c( ... )), allow_rename = FALSE , data = epi_arch $ DT ) )
70
70
if (length(arg ) == 0 ) {
71
71
first_non_key <- ! (names(epi_arch $ DT ) %in% c(key_colnames(epi_arch ), " version" ))
72
- arg <- syms( names(epi_arch $ DT )[first_non_key ][1 ])
72
+ arg <- names(epi_arch $ DT )[first_non_key ][1 ]
73
73
} else if (length(arg ) > 1 ) {
74
74
cli_abort(" Not currently implementing more than one column at a time. Run each separately" )
75
75
}
@@ -90,27 +90,28 @@ revision_summary <- function(epi_arch,
90
90
91
91
revision_behavior <-
92
92
epi_arch $ DT %> %
93
- select(c(geo_value , time_value , all_of(keys ), version , !! arg [[ 1 ]] ))
93
+ select(c(geo_value , time_value , all_of(keys ), version , !! arg ))
94
94
if (drop_nas ) {
95
95
# if we're dropping NA's, we should recompactify
96
96
revision_behavior <-
97
97
revision_behavior %> %
98
- filter(! is.na(!! arg [[ 1 ]] )) %> %
98
+ filter(! is.na(c_across( !! arg ) )) %> %
99
99
arrange(across(c(geo_value , time_value , all_of(keys ), version ))) %> % # need to sort before compactifying
100
100
compactify_tibble(c(keys , version ), compactify_tol )
101
101
} else {
102
102
revision_behavior <- epi_arch $ DT
103
103
}
104
- revision_behavior <- revision_behavior %> %
104
+ revision_behavior <-
105
+ revision_behavior %> %
105
106
mutate(lag = as.integer(version ) - as.integer(time_value )) %> % # nolint: object_usage_linter
106
107
group_by(across(all_of(keys ))) %> % # group by all the keys
107
108
summarize(
108
109
n_revisions = dplyr :: n() - 1 ,
109
110
min_lag = min(lag ), # nolint: object_usage_linter
110
111
max_lag = max(lag ), # nolint: object_usage_linter
111
- spread = spread_vec(!! arg [[ 1 ]] ),
112
- rel_spread = ( spread ) / max_no_na(!! arg [[ 1 ]] ), # nolint: object_usage_linter
113
- time_to = time_within_x_latest(lag , !! arg [[ 1 ]] , prop = within_latest ), # nolint: object_usage_linter
112
+ spread = spread_vec(pick( !! arg ) ),
113
+ rel_spread = spread / max_no_na(pick( !! arg ) ), # nolint: object_usage_linter
114
+ time_to = time_within_x_latest(lag , pick( !! arg ) , prop = within_latest ), # nolint: object_usage_linter
114
115
.groups = " drop"
115
116
) %> %
116
117
mutate(
@@ -125,7 +126,9 @@ revision_summary <- function(epi_arch,
125
126
cli_inform(" Min lag (time to first version):" )
126
127
difftime_summary(revision_behavior $ min_lag ) %> % print()
127
128
if (! drop_nas ) {
128
- total_na <- nrow(epi_arch $ DT %> % filter(is.na(!! arg [[1 ]]))) # nolint: object_usage_linter
129
+ total_na <- epi_arch $ DT %> %
130
+ filter(is.na(c_across(!! arg ))) %> % # nolint: object_usage_linter
131
+ nrow()
129
132
cli_inform(" Fraction of all versions that are `NA`:" )
130
133
cli_li(num_percent(total_na , nrow(epi_arch $ DT )))
131
134
}
@@ -171,9 +174,12 @@ revision_summary <- function(epi_arch,
171
174
return (revision_behavior )
172
175
}
173
176
177
+ # ' pull the value from lags when values starts indefinitely being within prop of it's last value.
178
+ # ' @param values this should be a 1 column tibble. errors may occur otherwise
174
179
# ' @keywords internal
175
180
time_within_x_latest <- function (lags , values , prop = .2 ) {
176
- latest_value <- values [length(values )]
181
+ values <- values [[1 ]]
182
+ latest_value <- values [[length(values )]]
177
183
close_enough <- abs(values - latest_value ) < prop * latest_value
178
184
# we want to ignore any stretches where it's close, but goes farther away later
179
185
return (get_last_run(close_enough , lags ))
0 commit comments