library(dplyr)
# Set up sample data tibble
data_tbl <- tibble::tribble(
~"study_id", ~"multi___1", ~"multi___2", ~"multi___3",
1, TRUE, FALSE, FALSE,
2, TRUE, TRUE, FALSE,
3, FALSE, FALSE, FALSE
)
# Set up sample metadata tibble
metadata_tbl <- tibble::tribble(
~"field_name", ~"field_type", ~"select_choices_or_calculations",
"study_id", "text", NA,
"multi___1", "checkbox", "1, Red | 2, Yellow | 3, Blue",
"multi___2", "checkbox", "1, Red | 2, Yellow | 3, Blue",
"multi___3", "checkbox", "1, Red | 2, Yellow | 3, Blue"
)
# Create sample supertibble
supertbl <- tibble::tribble(
~"redcap_form_name", ~"redcap_data", ~"redcap_metadata",
"tbl", data_tbl, metadata_tbl
)
class(supertbl) <- c("redcap_supertbl", class(supertbl))
# Combine checkboxes under column "multi"
combine_checkboxes(
supertbl = supertbl,
tbl = "tbl",
cols = starts_with("multi")
) %>%
dplyr::pull(redcap_data) %>%
dplyr::first()
if (FALSE) {
redcap_uri <- Sys.getenv("REDCAP_URI")
token <- Sys.getenv("REDCAP_TOKEN")
supertbl <- read_redcap(redcap_uri, token)
combine_checkboxes(
supertbl = supertbl,
tbl = "tbl",
cols = starts_with("col"),
multi_value_label = "Multiple",
values_fill = NA
)
}
Run the code above in your browser using DataLab