In recipe
, you can specify the roles variables will have by passing a character string that specifies roles such "outcome", "predictor", "case_weight", "ID", etc. For example, the iris
dataset variables have the following roles:
> recipe(Species ~ ., data = iris) %>% summary()
# A tibble: 5 × 4
variable type role source
<chr> <chr> <chr> <chr>
1 Sepal.Length numeric predictor original
2 Sepal.Width numeric predictor original
3 Petal.Length numeric predictor original
4 Petal.Width numeric predictor original
5 Species nominal outcome original
Ho do I retrieve the role of a specific variable? I haven't found a function for this. Since add_role()
, update_role()
, remove_role()
and even has_role()
exist, I would expect something like the following to be possible:
> recipe(Species ~ ., data = iris) %>% get_role(Species)
outcome
Does a function like this exist?