Skip to content

Change error to warning if many NAs in binom_ci #105

Description

@kelliemac

In using group_by() and summarize() with binom_ci(), I get errors if one of the groups has entirely NAs. For example:

df <- data.frame(
    Treatment = c(rep('T1', 4), rep('T2', 4)),
    Visit = c(rep(1, 2), rep(2, 2)),
    PUBID = c(rep(c(1, 2), 2), rep(c(3, 4), 2)),
    response = c(NA, NA, T, T, F, T, F, T)
)
df %>% group_by(Treatment, Visit) %>% summarize(binom_ci(response))

I would like for this code to still run in this case, and just return NAs for the results for the relevant group. For example, here is the wrapper that I am currently using:

binom_ci_allowing_missing_responses <- function(x) {
  if (any(!is.na(x))) { binom_ci(x) } else { data.frame(mean = NA, lower = NA, upper = NA, x = NA, n = 0, method = NA)}
}
df %>% group_by(Treatment, Visit) %>% summarize(binom_ci_allowing_missing_responses(response))

This could be adapted so that a warning is issued if we want to retain the FYI to the user that they are applying binom_ci() in a case where there are no response calls.

Possibly related discussion: #62

Metadata

Metadata

Assignees

Labels

No labels
No labels

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions