workflows icon indicating copy to clipboard operation
workflows copied to clipboard

pass calls through `forge_predictors()`

Open EmilHvitfeldt opened this issue 10 months ago • 1 comments
trafficstars

Reprex:

library(workflows)
library(parsnip)
library(recipes)

rec_spec <-
  recipe(mpg ~ ., data = mtcars) %>%
  update_role(disp, new_role = "date") %>%
  step_center(disp)

lm_spec <- linear_reg()

wf_spec <- workflow(rec_spec, lm_spec)

wf_fit <- fit(wf_spec, data = mtcars)

predict(wf_fit, mtcars %>% select(-disp))
#> Error in `hardhat::forge()`:
#> ! The required column "disp" is missing.

EmilHvitfeldt avatar Jan 10 '25 20:01 EmilHvitfeldt

without spending too much time right now, i suppect it might be somewhere in {hardhat} that is the issue. Here is the traceback


     ▆
  1. ├─stats::predict(wf_fit, mtcars %>% select(-disp))
  2. └─workflows:::predict.workflow(wf_fit, mtcars %>% select(-disp))
  3.   └─workflows:::forge_predictors(new_data, workflow)
  4.     ├─hardhat::forge(new_data, blueprint = mold$blueprint)
  5.     └─hardhat:::forge.data.frame(new_data, blueprint = mold$blueprint)
  6.       ├─hardhat::run_forge(blueprint, new_data = new_data, outcomes = outcomes)
  7.       └─hardhat:::run_forge.default_recipe_blueprint(...)
  8.         └─hardhat:::forge_recipe_default_clean(...)
  9.           └─hardhat:::forge_recipe_default_clean_extras(...)
 10.             └─hardhat:::map(...)
 11.               └─base::lapply(.x, .f, ...)
 12.                 └─hardhat (local) FUN(X[[i]], ...)
 13.                   └─hardhat::validate_column_names(data, cols, call = call)
 14.                     └─cli::cli_abort(...)
 15.                       └─rlang::abort(...)

EmilHvitfeldt avatar Jan 10 '25 22:01 EmilHvitfeldt