knitr::opts_chunk$set( collapse = TRUE, comment = "#>" )
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()
It 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.
import_instruments()
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")
Similar 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()
If you export data using the point-and-click tools built into REDCap you end up with two files, one contains R code the other data. When you run the code you end up with a dataset called data
which contains two copies of some of the information. For example, if you download the Nacho Craving Index you will see the ingredients variables, showing what ingredients people are craving, and a second copy of the variables that have .factor
tagged to the end of the names. The factor versions do not have the variable labels. So you will need to subset the data to drop them. The example below shows the process. Note we have copied the data
data frame to have a more meaningful name.
# This is the data produced by exporting using point-and-click REDCap export. manual_export <- data manual_export |> select(starts_with("ingredient")) |> # get all the ingredient variables select(-ends_with(".factor")) |> # drop the factor version of the ingredient variables make_choose_all_table("ingredient") # make the table
Any scripts or data that you put into this service are public.
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.