Skip to contents

The check functions identify duplicates, blank keys, unreconciled administrative GUIDs, out-of-range values and dates in the wrong order. They use the columns produced by the cleaners.

There is one function per stream:

Function Stream
checks_afp() cleaned AFP cases
checks_es() cleaned environmental samples
checks_hum_spec() cleaned human specimens
checks_sia() cleaned SIA campaigns
checks_virus() cleaned poliovirus positives

Running a check

Each checks_*() takes a cleaned table and returns a list: a summary tibble listing each configured check, plus one tibble of flagged rows per check that found problems. The example below creates a small cleaned AFP table with a few deliberate issues:

afp <- tibble::tibble(
  id = 1:5,
  epid = c("NIE-A-1", "NIE-A-1", "NIE-C-3", "NIE-D-4", "NIE-E-5"),
  adm0 = c("NIGERIA", "NIGERIA", "CHAD", "MALI", "NIGER"),
  adm1 = "p", adm2 = "d",
  paralysis_onset_date = c("2024-01-02", "2024-01-02", NA, "2999-01-01", "2024-03-03"),
  year_onset = c(2024L, 2024L, NA, 2999L, 2024L),
  classification_all = c("NPAFP", "NPAFP", "", "NPAFP", "NPAFP"),
  adm1_guid = c("g", "g", NA, "g", "g"),
  adm2_guid = "g",
  latitude = c(9.1, 9.1, 0, 9.1, 9.1),
  longitude = 7.2,
  age_months = c(24, 24, -5, 30, 36),
  notify_to_invest = c(1, 1, -1, 2, 1),
  adequate_stool = c("Yes", "Yes", "No", "Yes", "Yes")
)

res <- checks_afp(afp)
res$summary
#> # A tibble: 9 × 7
#>   check             domain severity n_flagged status missing_columns description
#>   <chr>             <chr>  <chr>        <int> <chr>  <chr>           <chr>      
#> 1 afp_missing_guid  AFP    error            1 check… ""              Cases miss…
#> 2 afp_duplicates    AFP    warning          2 check… ""              Duplicate …
#> 3 afp_no_onset      AFP    warning          1 check… ""              AFP cases …
#> 4 afp_no_classific… AFP    warning          1 check… ""              AFP cases …
#> 5 afp_future_onset  AFP    warning          1 check… ""              Onset date…
#> 6 afp_negative_int… AFP    warning          1 check… ""              Negative t…
#> 7 afp_empty_coords  AFP    info             1 check… ""              Cases with…
#> 8 afp_age_out_of_r… AFP    info             1 check… ""              Age in mon…
#> 9 afp_inadequate_s… AFP    info             1 check… ""              Cases flag…

The summary lists each check, its severity (error / warning / info, sorted worst first), and how many rows it flagged. Checks whose required columns are absent have status = "not_run", n_flagged = NA, and the missing column names in missing_columns. A check that ran and found no issues has n_flagged = 0.

Each check with flagged rows has a named table containing the record keys and the columns needed to review the issue:

names(res)
#>  [1] "summary"                "afp_duplicates"         "afp_no_onset"          
#>  [4] "afp_no_classification"  "afp_missing_guid"       "afp_empty_coords"      
#>  [7] "afp_future_onset"       "afp_age_out_of_range"   "afp_negative_intervals"
#> [10] "afp_inadequate_stool"
res$afp_missing_guid
#> # A tibble: 1 × 9
#>      id epid    adm0  adm1  adm2  paralysis_onset_date year_onset adm1_guid
#>   <int> <chr>   <chr> <chr> <chr> <chr>                     <int> <chr>    
#> 1     3 NIE-C-3 CHAD  p     d     <NA>                         NA <NA>     
#> # ℹ 1 more variable: adm2_guid <chr>

Export to Excel

write_checks_excel() turns a check result into one styled .xlsx workbook — a Summary tab plus one tab of flagged rows per failing check (navy headers, sized columns, inferred number formats). There is no versioning; the file is written straight to path.

write_checks_excel(res, "checks_afp.xlsx")

Automatic check workbooks in the pipeline

When you run the file-based pipeline with an output directory, run_pipeline_dir() writes a checks_<dataset>.xlsx workbook next to each polished_* output automatically — so a single call produces both the cleaned data and its quality report (see the End-to-end pipeline article). This step needs the optional openxlsx package; without it the checks are skipped with a message rather than failing the run.