Skip to contents

Internal function to validate the predictors argument. Requires the argument 'df' to be validated with validate_df().

Validates the 'predictors' argument to ensure it complies with the requirements of the package functions. It performs the following actions:

  • Stops if 'df' is NULL.

  • Stops if 'df' is not validated.

  • If 'predictors' is NULL, uses column names of 'df' as 'predictors' in the 'df' data frame.

  • Print a message if there are names in 'predictors' not in the column names of 'df', and returns only the ones in 'df'.

  • Stop if the number of numeric columns in 'predictors' is smaller than 'min_numerics'.

  • Print a message if there are zero-variance columns in 'predictors' and returns a new 'predictors' argument without them.

  • Tags the vector with the attribute validated = TRUE to let the package functions skip the data validation.

Usage

validate_predictors(
  df = NULL,
  response = NULL,
  predictors = NULL,
  quiet = FALSE
)

Arguments

df

(required; data frame, tibble, or sf) A data frame with responses and predictors. Default: NULL.

response

(optional; character string or vector) Name/s of response variable/s in df. Used in target encoding when it names a numeric variable and there are categorical predictors, and to compute preference order. Default: NULL.

predictors

(optional; character vector) Names of the predictors to select from df. If omitted, all numeric columns in df are used instead. If argument response is not provided, non-numeric variables are ignored. Default: NULL

quiet

(optional; logical) If FALSE, messages generated during the execution of the function are printed to the console Default: FALSE

Value

character vector: predictor names

Examples


data(
  vi,
  vi_predictors
  )

#validating example data frame
vi <- validate_df(
  df = vi
)

#validating example predictors
vi_predictors <- validate_predictors(
  df = vi,
  predictors = vi_predictors
)

#tagged as validated
attributes(vi_predictors)$validated
#> [1] TRUE