This function flags variables that have values exceeding the MIN
or MAX
listed in the data dictionary.
Value
Tibble, returned invisibly, containing: (1) Time (Time stamp); (2) Name (Name of the function); (3) Status (Passed/Failed); (4) Message (A copy of the message the function printed out); (5) Information (A sorted list of unique values that are either less than the MIN
value or greater than the MAX
value).
Examples
# Example 1
# Fail check (incorrectly flagging NA value codes -9999
# and -4444 as outside of the min max range)
data(ExampleA)
minmax_check(DD.dict.A, DS.data.A)
#> $Message
#> [1] "ERROR: some variables have values outside of the MIN to MAX range."
#>
#> $Information
#> # A tibble: 1 × 5
#> Trait Check ListedMin ListedMax OutOfRangeValues
#> <chr> <lgl> <dbl> <dbl> <list>
#> 1 PREGNANT FALSE 0 1 <int [2]>
#>
# View out of range values:
details <- minmax_check(DD.dict.A, DS.data.A)$Information
#> $Message
#> [1] "ERROR: some variables have values outside of the MIN to MAX range."
#>
#> $Information
#> # A tibble: 1 × 5
#> Trait Check ListedMin ListedMax OutOfRangeValues
#> <chr> <lgl> <dbl> <dbl> <list>
#> 1 PREGNANT FALSE 0 1 <int [2]>
#>
details[[1]]$OutOfRangeValues
#> [[1]]
#> [1] -9999 -4444
#>
# Attempt 2, specifying -9999 and -4444 as missing value
# codes so check works correctly
minmax_check(DD.dict.A, DS.data.A, non.NA.missing.codes=c(-9999, -4444))
#> $Message
#> [1] "Passed: when provided, all variables are within the MIN to MAX range."
#>
# Example 2
data(ExampleI)
minmax_check(DD.dict.I, DS.data.I, non.NA.missing.codes=c(-9999, -4444))
#> $Message
#> [1] "ERROR: some variables have values outside of the MIN to MAX range."
#>
#> $Information
#> # A tibble: 1 × 5
#> Trait Check ListedMin ListedMax OutOfRangeValues
#> <chr> <lgl> <dbl> <dbl> <list>
#> 1 PERCEIVED_CONFLICT FALSE 1 15 <int [11]>
#>
# View out of range values:
details <- minmax_check(DD.dict.I, DS.data.I, non.NA.missing.codes=c(-9999, -4444))$Information
#> $Message
#> [1] "ERROR: some variables have values outside of the MIN to MAX range."
#>
#> $Information
#> # A tibble: 1 × 5
#> Trait Check ListedMin ListedMax OutOfRangeValues
#> <chr> <lgl> <dbl> <dbl> <list>
#> 1 PERCEIVED_CONFLICT FALSE 1 15 <int [11]>
#>
details[[1]]$OutOfRangeValues
#> [[1]]
#> [1] 16 17 19 20 21 24 25 26 28 29 30
#>