Enforcement, kept separate from check_measurement_bounds() so that a bound
must be agreed before it is allowed to delete data. Run the check first, put
anything surprising to the provider as a question, and call this only for
bounds you are confident describe the impossible.
Usage
drop_out_of_bounds(
con,
tbl = "obs",
mt = NULL,
dataset_key = NULL,
type_col = "measurement_type",
value_col = "measurement_value",
quiet = FALSE
)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)- quiet
suppress the summary message
Value
The pre-delete tally from check_measurement_bounds(), invisibly,
restricted to the out_of_range rows that were acted on. n_bad is what was
deleted per type.
Details
DELETE rather than flag, for the same reason the -99 sentinel is deleted: in
a long-format table a row IS an assertion that a value was measured. A pH of
-10 left in place silently corrupts every mean, minimum and anomaly a consumer
computes downstream, and there is no in-band way to mark it as not-a-value.
Bounds are meant to be generous — impossible, not merely unusual — so this drops nothing an oceanographer would want to see. If it removes something interesting, the bound is wrong, not the reading.
Examples
if (FALSE) { # \dontrun{
oob <- drop_out_of_bounds(con, "ctd_measurement",
mt = here::here("metadata/measurement_type.csv"))
} # }