From ced5f70764de7263a0de857ede64b4749d22a3e0 Mon Sep 17 00:00:00 2001 From: fawda123 Date: Sun, 28 Jan 2024 14:11:59 -0500 Subject: [PATCH] added check in checkMWRresults if non-numeric in Quantitation Limit, excludes NA --- R/checkMWRresults.R | 12 ++++++++++++ man/checkMWRresults.Rd | 1 + tests/testthat/test-checkMWRresults.R | 8 ++++++++ vignettes/inputs.Rmd | 1 + 4 files changed, 22 insertions(+) diff --git a/R/checkMWRresults.R b/R/checkMWRresults.R index e0482566..2a4249e6 100644 --- a/R/checkMWRresults.R +++ b/R/checkMWRresults.R @@ -18,6 +18,7 @@ #' \item Activity Depth/Height Measure out of range: All depth values should be less than or equal to 1 meter / 3.3 feet or entered as Surface in the Activity Relative Depth Name column (warning only) #' \item Characteristic Name: Should match parameter names in the \code{Simple Parameter} or \code{WQX Parameter} columns of the \code{\link{paramsMWR}} data (warning only) #' \item Result Value: Should be a numeric value or a text value as AQL or BDL +#' \item Non-numeric Quantitation Limit: All values should be numbers, excluding missing values #' \item QC Reference Value: Should be a numeric value or a text value as AQL or BDL #' \item Result Unit: No missing entries in \code{Result Unit}, except pH which can be blank #' \item Single Result Unit: Each unique parameter in \code{Characteristic Name} should have only one entry in \code{Result Unit} (excludes entries for lab spikes reported as \code{\%} or \code{\% recovery}) @@ -197,6 +198,17 @@ checkMWRresults <- function(resdat, warn = TRUE){ stop(msg, '\n\tIncorrect entries in Result Value found: ', paste(tochk, collapse = ', '), ' in rows ', paste(rws, collapse = ', '), call. = FALSE) } message(paste(msg, 'OK')) + + # check Quantitation Limit for non-numeric (allows NA/missing) + msg <- '\tChecking for non-numeric values in Quantitation Limit...' + typ <- resdat$`Quantitation Limit` + chk <- !is.na(suppressWarnings(as.numeric(typ))) | is.na(typ) + if(any(!chk)){ + rws <- which(!chk) + tochk <- unique(typ[!chk]) + stop(msg, '\n\tNon-numeric entries in Quantitation Limit found: ', paste(tochk, collapse = ', '), ' in rows ', paste(rws, collapse = ', '), call. = FALSE) + } + message(paste(msg, 'OK')) # check QC Reference Values msg <- '\tChecking QC Reference Values...' diff --git a/man/checkMWRresults.Rd b/man/checkMWRresults.Rd index 187a7ea4..e45c0e93 100644 --- a/man/checkMWRresults.Rd +++ b/man/checkMWRresults.Rd @@ -33,6 +33,7 @@ The following checks are made: \item Activity Depth/Height Measure out of range: All depth values should be less than or equal to 1 meter / 3.3 feet or entered as Surface in the Activity Relative Depth Name column (warning only) \item Characteristic Name: Should match parameter names in the \code{Simple Parameter} or \code{WQX Parameter} columns of the \code{\link{paramsMWR}} data (warning only) \item Result Value: Should be a numeric value or a text value as AQL or BDL +\item Non-numeric Quantitation Limit: All values should be numbers, excluding missing values \item QC Reference Value: Should be a numeric value or a text value as AQL or BDL \item Result Unit: No missing entries in \code{Result Unit}, except pH which can be blank \item Single Result Unit: Each unique parameter in \code{Characteristic Name} should have only one entry in \code{Result Unit} (excludes entries for lab spikes reported as \code{\%} or \code{\% recovery}) diff --git a/tests/testthat/test-checkMWRresults.R b/tests/testthat/test-checkMWRresults.R index 02496545..c4558f73 100644 --- a/tests/testthat/test-checkMWRresults.R +++ b/tests/testthat/test-checkMWRresults.R @@ -73,6 +73,14 @@ test_that("Checking correct Characteristic Names", { }) test_that("Checking entries in Result Value", { + chk <- resdatchk + chk[23, 11] <- '<1' + chk[200, 11] <- 'a' + chk[250, 11] <- NA # does not trigger + expect_error(checkMWRresults(chk), 'Non-numeric entries in Quantitation Limit found: <1, a in rows 23, 200') +}) + +test_that("Checking entries in Quantitation Limit", { chk <- resdatchk chk[23, 9] <- '1.a09' chk[200, 9] <- 'MDL' diff --git a/vignettes/inputs.Rmd b/vignettes/inputs.Rmd index b250b1e0..badfbb0a 100644 --- a/vignettes/inputs.Rmd +++ b/vignettes/inputs.Rmd @@ -108,6 +108,7 @@ Several checks are run automatically when the data are imported. These file chec - **Activity Depth/Height Measure out of range**: All depth values should be less than or equal to 1 meter / 3.3 feet or entered as Surface in the Activity Relative Depth Name column (warning only) - **Characteristic Name**: Should match parameter names in the `Simple Parameter` or `WQX Parameter` column of the `paramsMWR` data (warning only) - **Result Value**: Should be a numeric value or a text value as AQL or BDL +- **Non-numeric Quantitation Limit**: All values should be numbers, excluding missing values - **QC Reference Value**: Any entered values should be numeric or a text value as AQL or BDL - **Result Unit**: No missing entries in `Result Unit`, except pH which can be blank - **Single Result Unit**: Each unique parameter in `Characteristic Name` should have only one entry in `Result Unit` (excludes entries for lab spikes reported as `%` or `% recovery`)