From 4fd4ec3ba5aaae3bfcd5be68f944b07c3b2ae792 Mon Sep 17 00:00:00 2001 From: Stuart Watt Date: Fri, 3 Nov 2023 15:30:39 -0300 Subject: [PATCH] Add uncertainty validation for external Resolves #352 ## Testing Notes Should now throw an error when any external file has an `uncertainty` value without a valid, present `unit_uncertainty` ## Technical Notes Adds uncertainty unit validation and checks --- R/import_functions.R | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/R/import_functions.R b/R/import_functions.R index 7aa1a67..254b29d 100644 --- a/R/import_functions.R +++ b/R/import_functions.R @@ -836,6 +836,18 @@ read_contaminants <- function(file, data_dir = ".", info) { colClasses = var_id[ok] ) + # additional validations + + # every valid `uncertainty` must have a valid `unit_uncertainty` + uncertainty_present <- which(complete.cases(data$uncertainty)) + uncertainty_present_valid_units <- + data$unit_uncertainty[uncertainty_present] %in% c("%", "U2", "SD") + if (! all(uncertainty_present_valid_units)) { + stop( + "Missing or invalid uncertainty units for specified uncertainty values. ", + "Please check that all uncertainty values have a valid unit: %, U2, or SD" + ) + } }