Adds a rule to the validation engine. A rule is a function fn(x, ctx) that
inspects a krt_tbl and returns a list of issues (each created with the
internal issue helper); the engine attaches the rule id, layer, standard, and
resolved severity.
Arguments
- rule_id
A unique rule identifier, e.g.
"struct-missing-name".- fn
The rule function
function(x, ctx)returning a list of issues.- layer
Either
"structural"or"semantic".- severity
Default severity: one of
"error","warning","note","info".- applies
A predicate
function(x); the rule runs only when it returnsTRUE(used by conditional rule packs).- standard
Optional reporting standard the rule enforces (e.g.
"cell-line-auth-minimum").- replace
Overwrite an existing rule with the same
rule_id? Defaults toFALSE, so a plugin cannot silently replace a built-in rule; passTRUEto deliberately override one.
Examples
# A rule inspects the table and returns a list of issues. This demonstration
# rule reports nothing, so registering it leaves validation results unchanged.
demo_rule <- function(x, ctx) list()
register_validator("demo-no-op", demo_rule, layer = "semantic",
severity = "note", replace = TRUE)
"demo-no-op" %in% list_validators()$rule_id
#> [1] TRUE
validate_krt(krt_example)$valid
#> [1] TRUE
