Skip to contents

This function searches for variables that appear to be incorrectly listed as TYPE decimal.

Usage

decimal_check(DD.dict, DS.data, verbose = TRUE)

Arguments

DD.dict

Data dictionary.

DS.data

Data set.

verbose

When TRUE, the function prints the Message out, as well as a list of variables that may be incorrectly labeled as TYPE decimal.

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 (Names of variables that are listed as TYPE decimal, but do not appear to be decimals).

Examples

# Example 1: Fail check
data(ExampleF)
decimal_check(DD.dict.F, DS.data.F)
#> $Message
#> [1] "ERROR: some variables listed as TYPE decimal do not appear to be decimals."
#> 
#> $Information
#> [1] "PERCEIVED_HEALTH"
#> 
print(integer_check(DD.dict.F, DS.data.F, verbose=FALSE))
#> # A tibble: 1 × 5
#>   Time                Function      Status Message                   Information
#>   <dttm>              <chr>         <chr>  <chr>                     <named lis>
#> 1 2023-09-27 11:01:15 integer_check Failed ERROR: some variables li… <chr [1]>  

# Example 2: Required pre-check fails
data(ExampleE)
decimal_check(DD.dict.E, DS.data.E)
#> $Note
#> [1] "Pre-check failed."
#> 
#> $Message
#> # A tibble: 2 × 2
#>   `r$Function`    `r$Message`                                                   
#>   <chr>           <chr>                                                         
#> 1 pkg_field_check Passed: package-level required fields TYPE, MIN, and MAX pres…
#> 2 dimension_check ERROR: the variable count differs between the data dictionary…
#> 
#> $Information
#> $Information$Information
#> $Information$Information$var.dim
#> Variables in dictionary       Variables in data 
#>                      30                      29 
#> 
#> $Information$Information$mismatches
#>   col_no                    Data        Dictionary
#> 1     18               HTN_dbGaP      BP_DIASTOLIC
#> 2     19              SMOKING_HX               HTN
#> 3     22 PHYSICAL_ACTIVITY_dbGaP        HEART_RATE
#> 4     26           HX_DEPRESSION        HX_ANXIETY
#> 5      5                  HEIGHT          PREGNANT
#> 6     20    LENGTH_SMOKING_YEARS   SMOKING_HISTORY
#> 7     23                   HX_DM PHYSICAL_ACTIVITY
#> 8     27          SOCIAL_SUPPORT     DEPRESSION_HX
#> 
#> $Information$Information$NamesMissingFromDictionary
#> [1] "HTN_dbGaP"               "SMOKING_HX"             
#> [3] "PHYSICAL_ACTIVITY_dbGaP" "HX_DEPRESSION"          
#> 
#> $Information$Information$NamesMissingFromData
#> [1] "PREGNANT"          "HTN"               "SMOKING_HISTORY"  
#> [4] "PHYSICAL_ACTIVITY" "DEPRESSION_HX"    
#> 
#> 
#> 
print(decimal_check(DD.dict.E, DS.data.E, verbose=FALSE))
#> # A tibble: 1 × 5
#>   Time                Function      Status        Message           Information 
#>   <dttm>              <chr>         <chr>         <chr>             <named list>
#> 1 2023-09-27 11:01:15 decimal_check Not attempted ERROR: Required … <named list>

# Example 3: Pass check
data(ExampleA)
decimal_check(DD.dict.A, DS.data.A)
#> $Message
#> [1] "Passed: all variables listed as TYPE decimal appear to be decimals."
#> 
print(decimal_check(DD.dict.A, DS.data.A, verbose=FALSE))
#> # A tibble: 1 × 5
#>   Time                Function      Status Message                   Information
#>   <dttm>              <chr>         <chr>  <chr>                     <named lis>
#> 1 2023-09-27 11:01:15 decimal_check Passed Passed: all variables li… <chr [1]>