checkMWRacc: Check data quality objective accuracy data

View source: R/checkMWRacc.R

checkMWRaccR Documentation

Check data quality objective accuracy data

Description

Check data quality objective accuracy data

Usage

checkMWRacc(accdat, warn = TRUE)

Arguments

accdat

input data frame

warn

logical to return warnings to the console (default)

Details

This function is used internally within readMWRacc to run several checks on the input data for completeness and conformance to WQX requirements

The following checks are made:

  • Column name spelling: Should be the following: Parameter, uom, MDL, UQL, Value Range, Field Duplicate, Lab Duplicate, Field Blank, Lab Blank, Spike/Check Accuracy

  • Columns present: All columns from the previous check should be present

  • Column types: All columns should be characters/text, except for MDL and UQL

  • Value Range column na check: The character string "na" should not be in the Value Range column, "all" should be used if the entire range applies

  • Unrecognized characters: Fields describing accuracy checks should not include symbols or text other than <=, \leq, <, >=, \geq, >, \pm, "%", "BDL", "AQL", "log", or "all"

  • Overlap in Value Range column: Entries in Value Range should not overlap for a parameter (excludes ascending ranges)

  • Gap in Value Range column: Entries in Value Range should not include a gap for a parameter, warning only

  • Parameter: Should match parameter names in the Simple Parameter or WQX Parameter columns of the paramsMWR data

  • Units: No missing entries in units (uom), except pH which can be blank

  • Single unit: Each unique Parameter should have only one type for the units (uom)

  • Correct units: Each unique Parameter should have an entry in the units (uom) that matches one of the acceptable values in the Units of measure column of the paramsMWR data

  • Empty columns: Columns with all missing or NA values will return a warning

Value

accdat is returned as is if no errors are found, otherwise an informative error message is returned prompting the user to make the required correction to the raw data before proceeding.

Examples

# accuracy path
accpth <- system.file('extdata/ExampleDQOAccuracy.xlsx', 
     package = 'MassWateR')

# accuracy data with no checks
accdat <- readxl::read_excel(accpth, na = c('NA', ''), col_types = 'text')
accdat <- dplyr::mutate(accdat, dplyr::across(-c(`Value Range`), ~ dplyr::na_if(.x, 'na'))) 
      
checkMWRacc(accdat)

massbays-tech/MassWateR documentation built on April 12, 2025, 7:53 p.m.