knitr::opts_chunk$set(echo = TRUE)
codified
PackageFirst, install the codified
package if necessary, and then load it into memory.
# if( !requireNamespace("codified", quietly = TRUE) ) # remotes::install_github(repo = "OuhscBbmc/codified") library(codified)
path <- system.file("misc/example-data-1.csv", package = "codified") col_types <- readr::cols_only( record_id = readr::col_integer(), name_last = readr::col_character(), dob = readr::col_date(format = ""), gender = readr::col_integer(), race = readr::col_integer(), ethnicity = readr::col_integer() ) ds <- readr::read_csv(path, col_types = col_types) |> dplyr::mutate( gender = as.character(gender), race = as.character(race), ethnicity = as.character(ethnicity) ) ds |> head(10) |> knitr::kable(caption = "Observed Dataset (first ten rows)") ds_lu_gender <- tibble::tribble( ~input, ~displayed , "0" , "Female" , "1" , "Male" , "U" , "Unknown/Not Reported" ) knitr::kable(ds_lu_gender, caption = "Gender Mapping") ds_lu_race <- tibble::tribble( ~input , ~displayed , "1" , "American Indian/Alaska Native" , "2" , "Asian" , "3" , "Native Hawaiian or Other Pacific Islander" , "4" , "Black or African American" , "5" , "White" , "M" , "More than One Race" , "6" , "Unknown or Not Reported" ) knitr::kable(ds_lu_race, caption = "Race Mapping") ds_lu_ethnicity <- tibble::tribble( ~input, ~displayed , "2" , "Not Hispanic or Latino" , "1" , "Hispanic or Latino" , "0" , "Unknown/Not Reported Ethnicity" ) knitr::kable(ds_lu_ethnicity, caption = "Ethnicity Mapping")
ds_summary_long <- codified::table_nih_enrollment( d = ds, d_lu_gender = ds_lu_gender, d_lu_race = ds_lu_race, d_lu_ethnicity = ds_lu_ethnicity ) knitr::kable(ds_summary_long, caption = "Counts of Each Subgroup")
codified::table_nih_enrollment_pretty( d = ds, d_lu_gender = ds_lu_gender, d_lu_race = ds_lu_race, d_lu_ethnicity = ds_lu_ethnicity )
A hosted (fake) clinical trial dataset demonstrates how to extract demographic data from REDCap and then present the demographic data in the NIH Inclusion Enrollment Report format.
First, install the REDCapR
package if necessary, and then load it into memory.
# if( !requireNamespace("REDCapR", quietly = TRUE) ) # remotes::install_github("OuhscBbmc/REDCapR") library(REDCapR)
Next, download the data from the REDCap database into the ds_2
data.frame. If you're running the most recent version of REDCapR (available on GitHub), the code will be:
ds_2 <- REDCapR::redcap_read( redcap_uri = "https://bbmc.ouhsc.edu/redcap/api/", # URL of REDCap Server. token = "F304DEC3793FECC3B6DEEFF66302CAD3", # User-specific token/password. guess_type = FALSE # Keep all variables as strings/characters. )$data
However CRAN policy understandably discourages vignettes from using "Internet resources" so this vignette mimics the code above with this local call. On your own computer, feel free to call that demonstration REDCap project.
ds_2 <- readr::read_csv( file = system.file("misc/example-data-2.csv", package = "codified"), col_types = readr::cols(.default = readr::col_character()) )
Now, convert these demographic data into a properly formatted NIH enrollment table. Pass the ds_lu_gender
, ds_lu_race
, and ds_lu_ethnicity
metadata, which was defined above. As a reminder, these translate values like 1
to Male
and 3
to Native Hawaiian or Other Pacific Islander
.
table_nih_enrollment_pretty( d = ds_2, d_lu_gender = ds_lu_gender, d_lu_race = ds_lu_race, d_lu_ethnicity = ds_lu_ethnicity )
Many observed datasets may collect race with a different set of levels. For instance in ds_3
, the American Indian
level is separate from the Alaska Native
level. In the first and second rows in the metadata below, the two levels are effectively combined into theAmerican Indian/Alaska Native
level, so it complies with the format of the NIH Enrollment table.
ds_lu_race_3 <- tibble::tribble( ~input , ~displayed , "American Indian" , "American Indian/Alaska Native" , # Combine w/ Alaska Native "Alaska Native" , "American Indian/Alaska Native" , # Combine w/ American Indian "Asian" , "Asian" , "Native Hawaiian" , "Native Hawaiian or Other Pacific Islander" , # Combine w/ Pacific Islanders "Pacific Islander" , "Native Hawaiian or Other Pacific Islander" , # Combine w/ Hawaiian "Black or African American" , "Black or African American" , "White" , "White" , "More than One Race" , "More than One Race" , "Unknown or Not Reported" , "Unknown or Not Reported" ) ds_3 <- tibble::tribble( ~subject_id, ~gender , ~race , ~ethnicity , 1L, "Female" , "American Indian", "Not Hispanic or Latino" , 2L, "Male" , "American Indian", "Not Hispanic or Latino" , 3L, "Male" , "American Indian", "Not Hispanic or Latino" , 4L, "Female" , "Alaska Native" , "Not Hispanic or Latino" , 5L, "Male" , "Alaska Native" , "Not Hispanic or Latino" , 6L, "Male" , "Alaska Native" , "Not Hispanic or Latino" , 7L, "Male" , "White" , "Not Hispanic or Latino" , 8L, "Male" , "White" , "Not Hispanic or Latino" ) table_nih_enrollment_pretty( d = ds_3, d_lu_race = ds_lu_race_3 )
Please share your opinions with us by creating an issue at https://github.com/OuhscBbmc/codified/issues.
Gender
instead of gender
). Issue #3.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.