validate_predictors: Validate Argument predictors

View source: R/validate.R

validate_predictorsR Documentation

Validate Argument predictors

Description

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

See Also

Other data_validation: validate_data_cor(), validate_data_vif(), validate_df(), validate_encoding_arguments(), validate_preference_order(), validate_response()

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


collinear documentation built on April 12, 2025, 1:36 a.m.