I looked at these two links:
I was able to get one thing down when creating the function, but different combinations of name injection weren't so clear. I put them in square brackets [ ]
where I'm struggling to find the solution.
original_data = data.frame(yy = runif(50, 1, 100),
xx = runif(50, 1, 100),
zz = runif(50, 1, 100))
y_var = 'yy'
variable_of_interest = 'xx'
print(paste0('Variable of interest is', variable_of_interest ))
select_variable_of_interest = function(ddff, aa, bb) {
ddff |>
select( {{ aa }} , {{ bb }} )
}
df = select_variable_of_interest(original_data, {{y_var}}, {{variable_of_interest}})
df_split = initial_split(df)
df_train = training(df_split)
recc = recipe( [y_var] ~ [variable_of_interest], data = df_train) |>
step_normalize( [variable_of_interest] )
The main problem seems to be with the recipe steps looking at this link: r - wrap tidymodels recipe into function - Stack Overflow
Is there a list of update_role
I can use? I would like to also use step_tokenize
for NLP, for example. Attempting to follow the example above:
f_recipe = function(dataa, yy, xx) {
recipe(dataa) |>
update_role({{yy}}, new_role = 'outcome')
update_role({{xx}}, new_role = 'predictor')
}
recc = f_recipe(df_train, [y_var], [variable_of_interest])
gives Error: $ operator is invalid for atomic vectors
error.