Skip to contents

Capture a logical rule the synthetic data must satisfy. Rules are enforced by synth() via rejection sampling at the unit grain (see Details).

Usage

rule(expr, scope = c("row", "unit"), label = NULL, table = NULL)

Arguments

expr

A logical expression over the column names, e.g. dbp <= sbp. With scope = "row" it is evaluated across a unit's rows and must be TRUE for every row. With scope = "unit" it is evaluated once per unit (the columns are that unit's rows in positional order) and must return TRUE – use this for temporal logic such as all(diff(los) >= 0). Missing (NA) results are treated as satisfied.

scope

"row" (default) or "unit".

label

Optional human-readable label; defaults to the deparsed expression.

table

Optional table name when supplying constraints to synth_linked(). NULL (default) infers the table from the referenced column names.

Value

A flexsynth_rule object.

Details

The expression is written in terms of the data's column names and is not evaluated when rule() is called – it is captured and checked later against the synthetic data.

Examples

# A row rule and a within-unit temporal rule.
rule(dbp <= sbp)
#> <flexsynth_rule [row]> dbp <= sbp
rule(all(diff(visit_time) > 0), scope = "unit")
#> <flexsynth_rule [unit]> all(diff(visit_time) > 0)