validate - asserts the following:
predictorsmust have numeric columns.
check - returns the following:
okA logical. Does the check pass?bad_classesA named list. The names are the names of problematic columns, and the values are the classes of the matching column.
Usage
validate_predictors_are_numeric(predictors)
check_predictors_are_numeric(predictors, ..., call = caller_env())Value
validate_predictors_are_numeric() returns predictors invisibly.
check_predictors_are_numeric() returns a named list of two components,
ok, and bad_classes.
Details
The expected way to use this validation function is to supply it the
$predictors element of the result of a call to mold().
Validation
hardhat provides validation functions at two levels.
check_*(): check a condition, and return a list. The list always contains at least one element,ok, a logical that specifies if the check passed. Each check also has check specific elements in the returned list that can be used to construct meaningful error messages.validate_*(): check a condition, and error if it does not pass. These functions call their corresponding check function, and then provide a default error message. If you, as a developer, want a different error message, then call thecheck_*()function yourself, and provide your own validation function.
See also
Other validation functions:
validate_column_names(),
validate_no_formula_duplication(),
validate_outcomes_are_binary(),
validate_outcomes_are_factors(),
validate_outcomes_are_numeric(),
validate_outcomes_are_univariate(),
validate_prediction_size()
Examples
# All good
check_predictors_are_numeric(mtcars)
#> $ok
#> [1] TRUE
#>
#> $bad_classes
#> list()
#>
# Species is not numeric
check_predictors_are_numeric(iris)
#> $ok
#> [1] FALSE
#>
#> $bad_classes
#> $bad_classes$Species
#> [1] "factor"
#>
#>
# This gives an intelligent error message
try(validate_predictors_are_numeric(iris))
#> Error in validate_predictors_are_numeric(iris) :
#> All predictors must be numeric.
#> ℹ The following is not:
#> "Species": <factor>
