Become an expert in R — Interactive courses, Cheat Sheets, certificates and more!
Get Started for Free

validate_predictors_are_numeric

Ensure predictors are all numeric


Description

validate - asserts the following:

  • predictors must have numeric columns.

check - returns the following:

  • ok A logical. Does the check pass?

  • bad_classes A 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)

Arguments

predictors

An object to check.

Details

The expected way to use this validation function is to supply it the $predictors element of the result of a call to mold().

Value

validate_predictors_are_numeric() returns predictors invisibly.

check_predictors_are_numeric() returns a named list of two components, ok, and bad_classes.

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 the check_*() function yourself, and provide your own validation function.

See Also

Examples

# All good
check_predictors_are_numeric(mtcars)

# Species is not numeric
check_predictors_are_numeric(iris)

# This gives an intelligent error message
try(validate_predictors_are_numeric(iris))

hardhat

Construct Modeling Packages

v0.1.5
MIT + file LICENSE
Authors
Davis Vaughan [aut, cre], Max Kuhn [aut], RStudio [cph]
Initial release

We don't support your browser anymore

Please choose more modern alternatives, such as Google Chrome or Mozilla Firefox.