Data Science Tapas

REDCap to R Markdown, reproducibly

Heidi Steiner

February 16, 2023

On Today’s Menu

  • Prep workspace
  • Discuss
    • REDCap + data extraction from an API

    • REDCapTidieR to “tidy” REDCap output

  • Hands-on
    • REDCap API Creation 🔌 and storage in .Renviron 🔐

    • REDCapTidieR to pull data 🧹

    • Render a reproducible .rmd report 🧶

Prepare RStudio

  • File > New R Markdown file
  • Replace contents with that of rmarkdownReport.Rmd
  • Install necessary packages
install.packages(c(
"knitr"
, "REDCapR"
, "REDCapTidieR"
, "tableone"
, "tidyverse"
, "usethis")) 

What is REDCap?

  • Free1 database solution for research
  • Secure and accessible from a web browser
  • Can collect “any type of data in any environment”
  • Particularly useful for compliance with 21 CFR Part 11, HIPAA, etc.
  • Requires little to get up and running, but offers complexity as needed

What is REDCap?

Record Status Dashboard

Front-End Data Entry UI

REDCap functions as a large data table, but data distribution can be complex depending on architectural choices. Repeating instances can create headaches on the backend.

The reproducibility problem

Screenshot of user interface with more than 15 options for exporting data

REDCap to R via API

Example Output via REDCapR

# Load applicable libraries:
library(dplyr)
library(REDCapR)

superheroes_db <- redcap_read_oneshot("https://redcap.uahs.arizona.edu/api/"
                                      , "superheroes_token"
                                      , verbose = FALSE)$data

superheroes_db %>% 
  glimpse()

The redcap problem

  • Empty data introduced as an artifact of repeating instruments

  • Data export is often times large and unwieldy

  • Missing metadata linking field association to instruments

  • Row identification is confusing and inconsistent

There are a number of problems with this which anyone here who has worked with repeating instruments or longitudinal REDCap projects has probably run into.

REDCapTidieR

Let’s Try! ▶️

  • REDCap API Creation 🔌 and storage in .Renviron 🔐

  • REDCapTidieR to pull data 🧹

  • Render a reproducible .rmd report 🧶

Buen Provecho!