Warning: There were 5 warnings in `mutate()`.
The first warning was:
ℹ In argument: `AESTDT = case_when(...)`.
Caused by warning:
! 3 failed to parse.
ℹ Run `dplyr::last_dplyr_warnings()` to see the 4 remaining warnings.
# Add study day categoriesae_with_categories <- ae_dates %>%mutate(# Create study day categoriesSTUDYDAY_PERIOD =case_when(is.na(AESTDY) ~"Unknown", AESTDY <=0~"Pre-treatment", AESTDY <=7~"Week 1", AESTDY <=14~"Week 2", AESTDY <=28~"Month 1",TRUE~"After Month 1" ),# Create early AE flag (within first 7 days)EARLY_AE =ifelse(AESTDY >=1& AESTDY <=7, "Y", "N") )print("✅ With study day categories:")
✅ Date parsing with lubridate (ymd, dmy, mdy)
✅ Study day calculations (AESTDY) with proper handling of missing data
✅ String manipulation with stringr (R4DS Chapter 14)
✅ Regular expressions for clinical data validation (R4DS Chapter 15)
✅ Factor management with forcats (R4DS Chapter 16)
✅ Clinical pattern matching and data quality validation
✅ Ordered factors for severity assessment and risk categorization
✅ Combined operations integrating dates, strings, regex, and factors
🔗 R4DS Integration Success
This module successfully integrated concepts from: - Chapter 14: Strings - Complete string manipulation toolkit - Chapter 15: Regular expressions - Advanced pattern matching for clinical validation
- Chapter 16: Factors - Categorical data management for clinical variables