0

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?

Zweifler
  • 375
  • 1
  • 4
  • 12
  • 1
    We do not currently have a function like that. You can get the complete role information either via `summary()` like you found here or via `$term_info$. If you would like to suggest this as a feature, feel free to [open an issue](https://github.com/tidymodels/recipes/issues) complete with a description of how you would like to use such a function, so we can gather feedback and prioritize it. – Julia Silge Nov 02 '21 at 20:32
  • @JuliaSilge Thank you, will look into suggesting this as soon as time permits. – Zweifler Nov 08 '21 at 19:14

0 Answers0