Verify that a set of linked tables is internally consistent: every table's
key identifies its rows uniquely, and every child row's foreign key resolves
to an existing parent row (no orphans). Works on a synth_linked() result or
on a raw named list of tables (supply keys in that case).
Arguments
- object
A
synth_linked_result, or a named list ofdata.frames.- keys
When
objectis a raw list of tables, a named list of key columns (as passed tosynth_linked()). Ignored for a result object.- verbose
Logical; print a short summary. Defaults to
TRUE.
Value
Invisibly, a report data.frame (one row per table, or per table and
collection when m > 1) with an ok attribute that is TRUE when there
are no duplicate keys and no orphan rows.
Examples
tabs <- list(
patients = data.frame(id = 1:3),
admissions = data.frame(id = c(1, 2, 9), admission_id = c(1, 1, 1))
)
check_linkage(tabs, keys = list(patients = "id",
admissions = c("id", "admission_id")))
#> Linkage problems found:
#> table parent rows duplicate_keys orphan_rows
#> 2 admissions patients 3 FALSE 1