library(tidyREDCap)
library(dplyr)REDCap exports a “choose all that apply” question into a series of similarly-named, binary indicator variables (i.e., the variables are equal to either “checked” or “unchecked”). For example, the following data represents a sample of responses to the Nacho Craving Index.
redcap <- readRDS(file = "./redcap.rds")
redcap %>%
select(starts_with("ingredients___")) %>%
head()
#> ingredients___1 ingredients___2 ingredients___3 ingredients___4
#> 1 Checked Checked Checked Checked
#> 2 Checked Checked Unchecked Checked
#> 3 Unchecked Unchecked Unchecked Unchecked
#> 4 Unchecked Unchecked Unchecked Unchecked
#> 5 Unchecked Unchecked Unchecked Unchecked
#> 6 Unchecked Unchecked Unchecked Unchecked
#> ingredients___5 ingredients___6 ingredients___7 ingredients___8
#> 1 Checked Checked Unchecked Checked
#> 2 Checked Unchecked Checked Checked
#> 3 Unchecked Unchecked Unchecked Unchecked
#> 4 Unchecked Unchecked Unchecked Unchecked
#> 5 Unchecked Unchecked Unchecked Unchecked
#> 6 Unchecked Unchecked Unchecked UncheckedIt is desirable to have a concise table showing how often each option was chosen.
See the Import All Instruments from a REDCap Project and Importing from REDCap vignettes for details/information.
If you pass the make_choose_all_table() function, the
name of a REDCap export, and the name of the choose all that apply
question question in REDCap, it will produce a concise frequency
count table.
make_choose_all_table(redcap, "ingredients")
#> # A tibble: 8 × 2
#> What Count
#> <chr> <dbl>
#> 1 Chips 9
#> 2 Yellow cheese 7
#> 3 Orange cheese 3
#> 4 White cheese 4
#> 5 Meat 5
#> 6 Beans 7
#> 7 Tomatoes 6
#> 8 Peppers 8Similar to the make_choose_one_table() function, we can
use this function inside an analysis pipeline. We can add the
kable() call to make the table publication quality.
redcap %>%
make_choose_all_table("ingredients") %>%
knitr::kable()| What | Count |
|---|---|
| Chips | 9 |
| Yellow cheese | 7 |
| Orange cheese | 3 |
| White cheese | 4 |
| Meat | 5 |
| Beans | 7 |
| Tomatoes | 6 |
| Peppers | 8 |