try_validator() evaluates a validator call and always returns a
validator-shaped object. If the validator errors, or if it returns an object
that does not contain rowid, variable, and reason, the error is
converted to a single validation issue.
Details
This is useful inside inspectors, where one broken validator should be reported to the user instead of stopping the whole validation step.
Examples
x = data.table::data.table(a = c(1, NA))
try_validator(
is.na_validator(x),
nam = "mandatory"
)
#> rowid variable reason
#> <int> <char> <char>
#> 1: 2 a mandatory
try_validator(
stop("broken validator"),
nam = "broken"
)
#> rowid variable
#> 1 <NA> <NA>
#> reason
#> 1 Validator “broken” returned an error: Error in try(..., silent = ...