This function if a wrappers from many utilities from the validate package.
Usage
validate_rules(
df,
...,
env = list(),
keep_rl_cols = NULL,
select_rl_rules = NULL
)
Arguments
- df
A data.frame or data.table to perform the analysis.
- ...
A comma-separated list of validating expressions
- env
A list with all the variables we want to make available in the validation rules.
- keep_rl_cols
Defining the columns to keep all data.table of broken row level rules.
- select_rl_rules
Defining which row level rules to return as data.table in the row_level_errors element.
Value
This function return a list of 2 elements:
summary: Return data.table with the result of all checks.
row_level_errors: Return a list of data.frames containing the column Broken Rule, the columns listed in the
keep_rl_cols
and the columns used to perform the validation.
Examples
validation_list <-
data.table::as.data.table(mtcars,
keep.rownames = "Car (Name)") |>
validate_rules("mpg low" = mpg > min_mpg,
"hp high" = hp < 200,
env = list(min_mpg = 15),
keep_rl_cols = "Car (Name)")
names(validation_list)
#> [1] "summary" "row_level_errors"
validation_list$summary
#> name items passes fails nNA error warning
#> <char> <int> <int> <int> <int> <lgcl> <lgcl>
#> 1: mpg.low 32 26 6 0 FALSE FALSE
#> 2: hp.high 32 25 7 0 FALSE FALSE
validation_list$row_level_errors
#> $mpg.low
#> Broken Rule Car (Name) mpg
#> <char> <char> <num>
#> 1: mpg.low Duster 360 14.3
#> 2: mpg.low Cadillac Fleetwood 10.4
#> 3: mpg.low Lincoln Continental 10.4
#> 4: mpg.low Chrysler Imperial 14.7
#> 5: mpg.low Camaro Z28 13.3
#> 6: mpg.low Maserati Bora 15.0
#>
#> $hp.high
#> Broken Rule Car (Name) hp
#> <char> <char> <num>
#> 1: hp.high Duster 360 245
#> 2: hp.high Cadillac Fleetwood 205
#> 3: hp.high Lincoln Continental 215
#> 4: hp.high Chrysler Imperial 230
#> 5: hp.high Camaro Z28 245
#> 6: hp.high Ford Pantera L 264
#> 7: hp.high Maserati Bora 335
#>