How to use tidy_select_recipe() in a custom function for undoing target engineering

I am trying to create a function to undo target engineering in a tidymodels workflow. I need to know which steps apply to the outcome variable to undo the transformations and I am trying to use the un-exported function eval_select_recipes(), which uses tidyselect::eval_select().

When I run this, I get an empty vectors:

library(tidyverse)
library(tidymodels)

data <- dplyr::select(mtcars, cyl, mpg, disp, hp)

mtcars_rec <- recipes::recipe(mpg ~ cyl + hp, data = data) %>%
  recipes::step_center(recipes::all_numeric(), -recipes::all_outcomes(), id = "centera") %>%
  recipes::step_scale(recipes::all_outcomes(), id = "scaleb")

eval_select_recipes(quos = mtcars_rec$steps[[1]]$terms,
                    data = data,
                    info = mtcars_rec$term_info)

# named character(0)

It works perfectly when I run prep(mtcars_rec) with the debugger, step inside the prep() function, and then run

eval_select_recipes(quos = mtcars_rec$steps[[1]]$terms,
                    data = data,
                    info = mtcars_rec$term_info)

# [1] "cyl" "hp"

In both cases, identical inputs are passed to eval_select() but one returns a length zero character and the other returns the correct named list.

This topic was automatically closed 21 days after the last reply. New replies are no longer allowed.

If you have a query related to it or one of the replies, start a new topic and refer back with a link.