recipes (version 0.1.0)

has_role: Role Selection

Description

has_role, all_predictors, and all_outcomes can be used to select variables in a formula that have certain roles. Similarly, has_type, all_numeric, and all_nominal are used to select columns based on their data type. See selections for more details. current_info is an internal function that is unlikely to help users while the others have limited utility outside of step function arguments.

Usage

has_role(match = "predictor", roles = current_info()$roles)

all_predictors(roles = current_info()$roles)

all_outcomes(roles = current_info()$roles)

has_type(match = "numeric", types = current_info()$types)

all_numeric(types = current_info()$types)

all_nominal(types = current_info()$types)

current_info()

Arguments

match

A single character string for the query. Exact matching is used (i.e. regular expressions won't work).

roles

A character string of roles for the current set of terms.

types

A character string of roles for the current set of data types

Value

Selector functions return an integer vector while current_info returns an environment with vectors vars, roles, and types.

Examples

Run this code
# NOT RUN {
data(biomass)

rec <- recipe(biomass) %>%
  add_role(carbon, hydrogen, oxygen, nitrogen, sulfur,
           new_role = "predictor") %>%
  add_role(HHV, new_role = "outcome") %>%
  add_role(sample, new_role = "id variable") %>%
  add_role(dataset, new_role = "splitting indicator")
recipe_info <- summary(rec)
recipe_info

has_role("id variable", roles = recipe_info$role)
all_outcomes(roles = recipe_info$role)
# }

Run the code above in your browser using DataLab