REDCapTidieR icon indicating copy to clipboard operation
REDCapTidieR copied to clipboard

[FEATURE] Add a function to make the default REDCap demographic race variables (7 choices) into a single race variable while allowing for an 8th choice, Multiple Races.

Open higgi13425 opened this issue 10 months ago • 2 comments

Feature Request Description

A clear and concise description of what the problem is. Ex. I'm always frustrated when [...]; It would be great to have [...], etc.

Proposed Solution

A function called singlevar_race Add a function to make the default REDCap demographic race variables (7 choices, TRUE or FALSE) into a single race variable while allowing for an 8th choice, Multiple Races. The solution below also creates a race_num variable for folks who prefer numeric vars.

singlevar_race <- function(data) { data |> pivot_longer(cols = race___1:race___7, names_to = "race_num", names_prefix = "race___", values_to = "true") |> filter(true == 1) |> arrange(subject_id) |> mutate(lead = lead(subject_id)) |> mutate(race_num = case_when( subject_id == lead ~ "8", TRUE ~ race_num)) |> distinct(subject_id, .keep_all = TRUE) |> mutate(race = case_when( race_num == '1' ~ "American Indian or Alaska Native", race_num == '2' ~ "Asian", race_num == '3' ~ "Black or African American", race_num == '4' ~ "Native Hawaiian or Other Pacific Islander", race_num == '5' ~ "Not Reported", race_num == '6' ~ "Unknown", race_num == '7' ~ "White", race_num == '8' ~ "Multiple Races")) |> select(-true, -lead) }

Describe alternatives you've considered I think this works, assuming

  1. you have a standard variable named subject_id
  2. you use the standard REDCap demographics

Additional Context

Add any other context or screenshots about the feature request here.

Checklist

  • [ ] The issue is atomic?
  • [ x] The issue description is documented
  • [ x] The issue title describes the problem succinctly
  • [ ] Developers are assigned to the issue - WORTH TESTING - possibly Richard or Stephan
  • [x ] Labels are assigned to the issue

higgi13425 avatar Apr 18 '24 12:04 higgi13425