knitr::opts_chunk$set( collapse = TRUE, comment = "#>" )
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 consise table showing how often each option was chosen.
redcapAPI package can be used to load data directly into R. To learn more about it, take a look here. Normally the code to automatically pull data with an API includes a person's secret code "key". Because I want to keep this hidden, I have hidden this API key in my user profile and the code below includes a call to
Sys.getenv() to grab the key. To learn more about working with APIs, look here. Also notice that the data is saved using the
saveRDS() function. REDCap data loaded with the API has the variable labels added as an extra attribute. To allow this vignette to run without sharing my secret key, I have saved the data to the package website.
rcon <- redcapAPI::redcapConnection( url = 'https://redcap.miami.edu/api/', token = Sys.getenv("NCI_API_Key") ) redcap <- redcapAPI::exportRecords(rcon)
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 consise frequency count table.
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 as well.
redcap %>% make_choose_all_table("ingredients") %>% knitr::kable()
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.