Learn R Programming

DCC (version 1.2.1)

dcc_execute: Execute actions on detected findings (Execute stage)

Description

Applies declarative actions to detected findings under the closed-loop rule: only cells and records named in the findings list are ever touched, and every change is logged at cell level (old value, new value, triggering check, method, timestamps, versions) carrying the exact finding_id that produced it. The whole plan is validated before any data changes -- unknown action IDs, unmapped recodes, missing or duplicated record ids, and group-level cell actions are errors. Findings without a mapped action are returned unhandled rather than silently flagged or dropped. A cell action made inapplicable by an earlier record exclusion is recorded as skipped. The input is never modified.

Usage

dcc_execute(x, findings, actions = list(), id_var = NULL,
  default = "flag", ruleset_hash = NULL)

Value

A dcc_result: list with data (the new dcc_data version), audit (cell-level audit log whose first column is finding_id), unhandled (findings with no explicit action), dispositions (one terminal row per finding), report_profile (aggregate pre-cleaning types, missingness, and complete frequency counts without raw rows), and n_excluded. Accessors: dcc_audit_log, dcc_cleaned, dcc_dispositions.

Arguments

x

A dcc_data object or data.frame.

findings

A dcc_findings table from the Detect stage with unique, non-empty finding_id values.

actions

Named list mapping check_ids to actions: "exclude", "set_na", "flag", or list(action = "recode", map = c(old = new)). Every name must match a check_id in findings; unknown action IDs are an error.

id_var

Name of the record-id column matching the findings' record_id, or NULL for row numbers. When supplied, the column must contain non-missing, unique ids.

default

Deprecated and no longer applied: findings without an explicit action are returned unhandled rather than auto-dispositioned. Retained only for call compatibility.

ruleset_hash

Optional rule-file hash stamped into the audit log (taken from the findings' dcc_data attribute when available).

Examples

Run this code
df <- data.frame(sid = c("S1", "S2"), score = c(50, 150))
f <- dcc_findings("S2", variable = "score", check_id = "R001",
                  evidence = "out of range", severity = "fail")
res <- dcc_execute(df, f, actions = list(R001 = "set_na"),
                   id_var = "sid")
dcc_audit_log(res)

Run the code above in your browser using DataLab