I would like to use case_when
from dplyr
in order to select a column to change its role for a tidymodels
recipe.
What am I doing wrong? In the following MWE an ID-role should be assigned to the column "b":
library(tidyverse)
library(tidymodels)
# dummy data
a = seq(1:3)
b = seq(4:6)
c = seq(7:9)
df <- data.frame(a,b,c)
# filter variable
col_name = "foo"
rec <- recipe(a ~., data = df) %>%
update_role(
case_when(
col_name == "foo" ~ b, # Not working too: .$b, df$b
col_name == "foo2" ~ c),
new_role = "ID")
rec