Skip to contents

Check censored data

Usage

checkMWRcens(censdat, warn = TRUE)

Arguments

censdat

input data frame for results

warn

logical to return warnings to the console (default)

Value

censdat 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. Checks with warnings can be fixed at the discretion of the user before proceeding.

Details

This function is used internally within readMWRcens to run several checks on the input data for completeness and conformance.

The following checks are made:

  • Column name spelling: Should be the following: Parameter, Missed and Censored Records

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

  • Non-numeric Missed and Censored Records: All values should be numbers, excluding missing values

  • Negative Missed and Censored Records: All values should be greater than or equal to zero

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

Examples

censpth <- system.file('extdata/ExampleCensored.xlsx', package = 'MassWateR')

censdat <- suppressWarnings(readxl::read_excel(censpth, na = c('NA', 'na', ''), guess_max = Inf)) 
             
checkMWRcens(censdat)
#> Running checks on censored data...
#> 	Checking column names... OK
#> 	Checking all required columns are present... OK
#> 	Checking for non-numeric values in Missed and Censored Records... OK
#> 	Checking for negative values in Missed and Censored Records... OK
#> 	Checking Parameter Name formats... OK
#> 
#> All checks passed!
#> # A tibble: 3 × 2
#>   Parameter `Missed and Censored Records`
#>   <chr>                             <dbl>
#> 1 pH                                   12
#> 2 DO                                    1
#> 3 Nitrate                               0