Check measured values against the registry's declared bounds
Source:R/bounds.R
check_measurement_bounds.RdThe standard bounds check for an ingest notebook and for the release. Compares
every value in a long-format measurement table against valid_min /
valid_max from metadata/measurement_type.csv, and reports the types that
violate a bound alongside the types that declare none — see the note in
R/bounds.R for why the second matters at least as much as the first.
Usage
check_measurement_bounds(
con,
tbl = "obs",
mt = NULL,
dataset_key = NULL,
type_col = "measurement_type",
value_col = "measurement_value",
depth_col = NULL,
include_undeclared = TRUE
)Arguments
- con
DuckDB connection
- tbl
table or view to check (default
"obs"). Works on any long-format table: the per-dataset{dataset}_measurementduring wrangling, the emittedobs, orsample_measurement.- mt
the measurement registry: a data.frame, a path to
measurement_type.csv, orNULL(default) to read ameasurement_typetable fromcon.- dataset_key
optional
dataset_keyto filter to, whentblholds more than one dataset. Ignored iftblhas nodataset_keycolumn.- type_col, value_col
column names (default
measurement_type/measurement_value)- depth_col
optional depth column enabling the depth-window check against
valid_depth_min_m/valid_depth_max_m— the depth over which a type is defined. A non-null value outside that window is a finding: it means the type was emitted where the registry says it does not exist.- include_undeclared
report types with no declared bound (default TRUE). Set FALSE for a violations-only view.
Value
A tibble, one row per measurement type present, ordered worst-first (violations by count, then undeclared by count):
statusout_of_range(declared and violated),undeclared(nothing declared),ok(declared and respected)n_total,n_bad,pct_badrows checked, rows outside, percent
n_low,n_highsplit by which bound was broken
v_min,v_maxobserved range, for proposing a bound
valid_min,valid_maxwhat the registry declares
n_outside_depthpresent only when
depth_colis givenfindinga one-line summary, ready to paste into the
contextcolumn of aquestions.csvrow
Details
Read-only: it deletes and rewrites nothing. Enforce with
drop_out_of_bounds(), and only once the bound is agreed.
Bounds may be one-sided. valid_min = 0 with no valid_max is the useful case
for abundances and counts — "never negative" is agreeable without knowing the
ceiling — and a type is undeclared only when both are missing.
See also
drop_out_of_bounds() to enforce, bounds_datatable() to render,
read_measurement_type() for the registry, register_measurement_types()
to declare a new bound.
Examples
if (FALSE) { # \dontrun{
b <- check_measurement_bounds(
con, "ctd_measurement",
mt = here::here("metadata/measurement_type.csv"))
bounds_datatable(b)
} # }