Skip to content

Commit

Permalink
added check in checkMWRresults if non-numeric in Quantitation Limit, …
Browse files Browse the repository at this point in the history
…excludes NA
  • Loading branch information
fawda123 committed Jan 28, 2024
1 parent a5fe5f8 commit ced5f70
Show file tree
Hide file tree
Showing 4 changed files with 22 additions and 0 deletions.
12 changes: 12 additions & 0 deletions R/checkMWRresults.R
Original file line number Diff line number Diff line change
Expand Up @@ -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})
Expand Down Expand Up @@ -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...'
Expand Down
1 change: 1 addition & 0 deletions man/checkMWRresults.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

8 changes: 8 additions & 0 deletions tests/testthat/test-checkMWRresults.R
Original file line number Diff line number Diff line change
Expand Up @@ -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'
Expand Down
1 change: 1 addition & 0 deletions vignettes/inputs.Rmd
Original file line number Diff line number Diff line change
Expand Up @@ -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`)
Expand Down

0 comments on commit ced5f70

Please sign in to comment.