Skip to content

Commit cdee6c6

Browse files
authored
Merge pull request #1296 from cmu-delphi/combine-filter
Combine `summarize_*` filter in surveys aggregation
2 parents bcdbcdd + 4ee0a08 commit cdee6c6

File tree

2 files changed

+8
-2
lines changed

2 files changed

+8
-2
lines changed

facebook/delphiFacebook/R/aggregate.R

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -181,7 +181,10 @@ summarize_indicators_day <- function(day_df, indicators, target_day, geo_level,
181181

182182
# Copy only columns we're using.
183183
select_cols <- c(metric, var_weight, "weight_in_location")
184-
ind_df <- sub_df[, select_cols, with=FALSE][!is.na(sub_df[[var_weight]]) & !is.na(sub_df[[metric]]), ]
184+
# This filter uses `x[, cols, with=FALSE]` rather than the newer
185+
# recommended `x[, ..cols]` format to take advantage of better
186+
# performance. Switch to using `..` if `with` is deprecated in the future.
187+
ind_df <- sub_df[!is.na(sub_df[[var_weight]]) & !is.na(sub_df[[metric]]), select_cols, with=FALSE]
185188

186189
if (nrow(ind_df) > 0)
187190
{

facebook/delphiFacebook/R/contingency_aggregate.R

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -336,7 +336,10 @@ summarize_aggregations_group <- function(group_df, aggregations, target_group, g
336336

337337
# Copy only columns we're using.
338338
select_cols <- c(metric, var_weight, "weight_in_location")
339-
agg_df <- group_df[, select_cols, with=FALSE][!is.na(eval(as.name(metric))), ]
339+
# This filter uses `x[, cols, with=FALSE]` rather than the newer recommended
340+
# `x[, ..cols]` format to take advantage of better performance. Switch to
341+
# using `..` if `with` is deprecated in the future.
342+
agg_df <- group_df[!is.na(eval(as.name(metric))), select_cols, with=FALSE]
340343

341344
if (nrow(agg_df) > 0) {
342345
s_mix_coef <- params$s_mix_coef

0 commit comments

Comments
 (0)