Skip to content

Commit c1c954e

Browse files
authored
Merge pull request #1369 from cmu-delphi/contingency-missing-val-tables
Don't report contingency table if responses for supporting items are all `NA`
2 parents dc9d800 + f9a7d98 commit c1c954e

File tree

1 file changed

+7
-2
lines changed

1 file changed

+7
-2
lines changed

facebook/delphiFacebook/R/contingency_aggregate.R

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -158,15 +158,20 @@ post_process_aggs <- function(df, aggregations, cw_list) {
158158
metric_cols <- unique(aggregations$metric)
159159

160160
cols_check_available <- unique(c(group_vars[group_vars != "geo_id"], metric_cols))
161-
available <- cols_check_available %in% names(df)
161+
available <- unlist(
162+
lapply(cols_check_available, function(col) {
163+
# Exists in dataframe and column is not only NAs
164+
col %in% names(df) && !all(is.na( unique(df[[col]] )))
165+
})
166+
)
162167
cols_not_available <- cols_check_available[ !available ]
163168
for (col_var in cols_not_available) {
164169
# Remove from aggregations
165170
aggregations <- aggregations[aggregations$metric != col_var &
166171
!mapply(aggregations$group_by,
167172
FUN=function(x) {col_var %in% x}), ]
168173
msg_plain(paste0(
169-
col_var, " is not defined. Removing all aggregations that use it. ",
174+
col_var, " is not available or not defined. Removing all aggregations that use it. ",
170175
nrow(aggregations), " remaining")
171176
)
172177
}

0 commit comments

Comments
 (0)