Skip to content

Commit 572819f

Browse files
committed
unify group_vars name between funcs
1 parent f472223 commit 572819f

File tree

1 file changed

+9
-9
lines changed

1 file changed

+9
-9
lines changed

facebook/delphiFacebook/R/contingency_aggregate.R

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,7 @@ produce_aggregates <- function(df, aggregations, cw_list, params) {
5555

5656
agg_groups <- unique(aggregations[c("group_by", "geo_level")])
5757

58-
# For each unique combination of groupby_vars and geo level, run aggregation process once
58+
# For each unique combination of group_vars and geo level, run aggregation process once
5959
# and calculate all desired aggregations on the grouping. Rename columns. Save
6060
# to individual files
6161
for (group_ind in seq_along(agg_groups$group_by)) {
@@ -248,16 +248,16 @@ summarize_aggs <- function(df, crosswalk_data, aggregations, geo_level, params)
248248
## inefficient; profiling shows the cost to be negligible, so shut it up
249249
df <- suppressWarnings(inner_join(df, crosswalk_data, by = "zip5"))
250250

251-
groupby_vars <- aggregations$group_by[[1]]
251+
group_vars <- aggregations$group_by[[1]]
252252

253-
if (all(groupby_vars %in% names(df))) {
254-
unique_group_combos <- unique(df[, groupby_vars, with=FALSE])
253+
if (all(group_vars %in% names(df))) {
254+
unique_group_combos <- unique(df[, group_vars, with=FALSE])
255255
unique_group_combos <- unique_group_combos[complete.cases(unique_group_combos)]
256256
} else {
257257
msg_plain(
258258
sprintf(
259259
"not all of groupby columns %s available in data; skipping aggregation",
260-
paste(groupby_vars, collapse=", ")
260+
paste(group_vars, collapse=", ")
261261
))
262262
}
263263

@@ -268,7 +268,7 @@ summarize_aggs <- function(df, crosswalk_data, aggregations, geo_level, params)
268268
## Set an index on the groupby var columns so that the groupby step can be
269269
## faster; data.table stores the sort order of the column and
270270
## uses a binary search to find matching values, rather than a linear scan.
271-
setindexv(df, groupby_vars)
271+
setindexv(df, group_vars)
272272

273273
calculate_group <- function(ii) {
274274
target_group <- unique_group_combos[ii]
@@ -301,15 +301,15 @@ summarize_aggs <- function(df, crosswalk_data, aggregations, geo_level, params)
301301
## Do post-processing.
302302
for (row in seq_len(nrow(aggregations))) {
303303
aggregation <- aggregations$id[row]
304-
groupby_vars <- aggregations$group_by[[row]]
304+
group_vars <- aggregations$group_by[[row]]
305305
post_fn <- aggregations$post_fn[[row]]
306306

307307
dfs_out[[aggregation]] <- dfs_out[[aggregation]][
308-
rowSums(is.na(dfs_out[[aggregation]][, c("val", "sample_size", groupby_vars)])) == 0,
308+
rowSums(is.na(dfs_out[[aggregation]][, c("val", "sample_size", group_vars)])) == 0,
309309
]
310310

311311
if (geo_level == "county") {
312-
df_megacounties <- megacounty(dfs_out[[aggregation]], params$num_filter, groupby_vars)
312+
df_megacounties <- megacounty(dfs_out[[aggregation]], params$num_filter, group_vars)
313313
dfs_out[[aggregation]] <- bind_rows(dfs_out[[aggregation]], df_megacounties)
314314
}
315315

0 commit comments

Comments
 (0)