CLiREN-LMS
Data Cleaning and Preparation in R

Cleaning Logs and Query Outputs

Code Example 1

30-45 minutes Applied Step 7 of 9
Code

Code Example 1

7 / 9
Code

Code Example 1

r

missing_consent_queries <- enrollment_prepared |>
  filter(is.na(consent_date)) |>
  transmute(
    participant_id,
    site,
    rule_id = "ENR_MISS_CONSENT_DATE",
    variable = "consent_date",
    query_text = "Please enter or verify the informed consent date.",
    priority = "High"
  )

age_queries <- enrollment_prepared |>
  filter(age_years_derived < 18 | age_years_derived > 120) |>
  transmute(
    participant_id,
    site,
    rule_id = "ENR_AGE_RANGE",
    variable = "age_years_derived",
    query_text = "Derived age is outside the expected adult range. Please verify date of birth and enrollment date.",
    priority = "Medium"
  )

date_queries <- enrollment_prepared |>
  filter(enrollment_date < consent_date) |>
  transmute(
    participant_id,
    site,
    rule_id = "ENR_DATE_SEQUENCE",
    variable = "enrollment_date",
    query_text = "Enrollment date appears to occur before consent date. Please verify both dates.",
    priority = "High"
  )

query_listing <- bind_rows(
  missing_consent_queries,
  age_queries,
  date_queries
) |>
  arrange(site, participant_id, rule_id)