diff --git a/R/import_functions.R b/R/import_functions.R index e44a5a6..3690fe6 100644 --- a/R/import_functions.R +++ b/R/import_functions.R @@ -894,6 +894,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" + ) + } }