Skip to contents

This function checks for potential errors in the VALUES columns by ensuring (1) required format of VALUE=MEANING (e.g., 0=Yes or 1=No); (2) no leading/trailing spaces near the equals sign; (3) all variables of TYPE encoded have VALUES entries; and (4) all variables with VALUES entries are listed as TYPE encoded.

Usage

values_check(DD.dict, verbose = TRUE)

Arguments

DD.dict

Data dictionary.

verbose

When TRUE, the function prints the Message out, as well as a list of variables that fail one of the values checks.

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 (Details of which checks passed/failed for which value=meaning instances).

Examples

# Example 1: Fail check
data(ExampleE)
values_check(DD.dict.E)
#> $Message
#> [1] "ERROR: at least one VALUES check flagged potentials issues. See Information for more details."
#> 
#> $Information
#>    column_name values.check            vname                   type
#> 4      VALUES3        FALSE         CUFFSIZE integer, encoded value
#> 6       VALUES        FALSE              HTN integer, encoded value
#> 7       VALUES        FALSE PERCEIVED_HEALTH integer, encoded value
#> 9      VALUES5        FALSE               28 integer, encoded value
#> 10     VALUES4        FALSE               28 integer, encoded value
#> 12     VALUES2        FALSE               16 integer, encoded value
#> 14      VALUES        FALSE           RESIST integer, encoded value
#> 15      VALUES        FALSE        SAMPLE_ID                integer
#> 16      VALUES        FALSE              SEX                integer
#>                                                   problematic_description
#> 4                                                           2 means large
#> 6                                                          0 indicates no
#> 7  Between 1 and 10 with higher values indicating better perceived health
#> 9                                                        5 = a great deal
#> 10                                                        4 = quite a bit
#> 12                                                              1 =medium
#> 14                                                                   <NA>
#> 15                                                    -9999=missing value
#> 16                                                                 0=male
#>                                                                         check
#> 4                  Check 1: Is an equals sign present for all values columns?
#> 6                  Check 1: Is an equals sign present for all values columns?
#> 7                  Check 1: Is an equals sign present for all values columns?
#> 9  Check 2: Are there any leading/trailing spaces near the first equals sign?
#> 10 Check 2: Are there any leading/trailing spaces near the first equals sign?
#> 12 Check 2: Are there any leading/trailing spaces near the first equals sign?
#> 14  Check 3: Do all variables of TYPE encoded have at least one VALUES entry?
#> 15            Check 4: Are all variables with VALUES entries of TYPE encoded?
#> 16            Check 4: Are all variables with VALUES entries of TYPE encoded?
#> 
print(values_check(DD.dict.E, verbose=FALSE))
#> # A tibble: 1 × 5
#>   Time                Function     Status Message                    Information
#>   <dttm>              <chr>        <chr>  <chr>                      <named lis>
#> 1 2023-09-27 11:01:22 values_check Failed ERROR: at least one VALUE… <df>       

# Example 2: Pass check
data(ExampleA)
values_check(DD.dict.A)
#> $Message
#> [1] "Passed: all four VALUES checks look good."
#> 
#> $Information
#>   check.name                                                 check.description
#> 1    Check 1                 Is an equals sign present for all values columns?
#> 2    Check 2 Are there any leading/trailing spaces near the first equals sign?
#> 3    Check 3  Do all variables of TYPE encoded have at least one VALUES entry?
#> 4    Check 4            Are all variables with VALUES entries of TYPE encoded?
#>   check.status
#> 1       Passed
#> 2       Passed
#> 3       Passed
#> 4       Passed
#> 
print(values_check(DD.dict.A, verbose=FALSE))
#> # A tibble: 1 × 5
#>   Time                Function     Status Message                    Information
#>   <dttm>              <chr>        <chr>  <chr>                      <named lis>
#> 1 2023-09-27 11:01:22 values_check Passed Passed: all four VALUES c… <df>