Combines the raw POLIS activity and sub-activity tables into one analytic SIA
dataset and standardises it the same way clean_afp() / clean_es() do:
canonical snake_case names (via the crosswalk + janitor);
the sub-activity grain enriched with its parent campaign: the activity table is restricted to the sub-activity codes actually present, then joined onto each sub-activity by
sia_sub_activity_code(parent columns that clash take an_activitysuffix; the redundant geographic parent copies – region, ISO, admin name/GUID, shape id, IST – are dropped);every campaign/planning date parsed to
Dateand sanitised with the same "sensible date" rule (a value beforemin_yearor in the future is a data-entry error and set toNA); audit timestamps stay ISO strings for the keep-latest dedup;year_start/month_startfrom the sanitiseddate_from(the sub-activity start);normalised admin names and – when a
shapeis supplied – admin-GUID reconciliation against it (keyed onyear_start), exactly asclean_es()uses it;GUIDs emitted in the braced upper-case POLIS form and one row per POLIS
id(latest bylast_update_date);campaign rounds: within each district (
adm2_guid) xvaccine_type, sub-activities are ordered bydate_fromand split into rounds wherever the gap to the previous campaign exceedsround_gap_days, giving a sequentialround_num;max_round_date/last_campaignflag each district's most recent campaign.
Usage
clean_sia(
activity,
subactivity = NULL,
cfg = polis_active_config(),
shape = NULL,
round_gap_days = 21L,
reference_date = Sys.Date(),
cache_dir = NULL,
cache_key = NULL,
verbose = TRUE
)Arguments
- activity
A raw POLIS activity data frame.
- subactivity
Optional raw POLIS sub-activity data frame. When supplied it is the grain of the output and
activityis joined onto it; whenNULLthe activity table is cleaned on its own.- cfg
A
polis_config()object. Defaults topolis_active_config()– the config most recently built bypolis_config()this session – so a no-cfgcall inherits the active session settings rather than fresh defaults.- shape
Optional district shape used to reconcile admin names/GUIDs via
reconcile_admin_guids()(keyed onyear_start), exactly asclean_es()uses it. Either a long ADM2 attribute table or the polygon layer (expanded to its long form here). DefaultNULL(no shape-based recovery).- round_gap_days
Maximum number of days between consecutive campaigns in the same district and
vaccine_typefor them to count as one round; a larger gap starts a new round. Default21.- reference_date
Date treated as "today" when sanitising campaign dates: any parsed date after it is nulled as a data-entry error (default
Sys.Date()). It is part of the cache key, so a run on a later day does not return a stale cached table in which then-future dates are stillNA. Pin it for reproducible output.- cache_dir
Optional directory for an opt-in, content-addressed cache. When set, the cleaned table is written to (and on a later identical call read back from) a
qs2file whose name hashes every input that affects the output (activity,subactivity,cfg,shape,round_gap_days,reference_date); any change to an input recomputes and writes a new entry. DefaultNULL(no caching).- cache_key
Optional cheap stand-in for the raw tables in the cache key (e.g. a download snapshot id). When supplied, the key is built from it instead of hashing
activity/subactivity, avoiding a full content hash of large inputs;cfg,shapeandround_gap_daysstill contribute. Ignored unlesscache_diris set. DefaultNULL(hash the tables).- verbose
Emit cli progress messages for each phase. Default
TRUE.
Value
A tibble of cleaned SIA records, one row per POLIS id, with columns
ordered id -> location -> time -> other. Derived columns (year_start,
month_start, round_num, max_round_date, last_campaign) are added
only when their source columns are present.
Examples
activity <- data.frame(
Id = 1,
SIASubActivityCode = "S1",
LastUpdateDate = "2024-03-01",
VaccineType = "bOPV",
check.names = FALSE
)
subactivity <- data.frame(
Id = 10,
SIASubActivityCode = "S1",
LastModificationDate = "2024-03-01",
DateFrom = "2024-03-10",
Admin0Name = "NIGERIA",
check.names = FALSE
)
clean_sia(activity, subactivity, verbose = FALSE)
#> # A tibble: 1 × 10
#> id adm0 last_modification_date date_from last_update_date
#> <dbl> <chr> <date> <date> <date>
#> 1 10 NIGERIA 2024-03-01 2024-03-10 2024-03-01
#> # ℹ 5 more variables: sia_sub_activity_code <chr>, id_activity <dbl>,
#> # vaccine_type <chr>, year_start <dbl>, month_start <dbl>
