tidymodels update_role() error using predict() without variable without a predictor role

When building a model, I have some variables I use for evaluation, so I make their role "evaluative", but these variables won't be there later when I use the model in production. Is there something I can do to use them but not expect them later? Below is a reprex:

library(tidymodels)
library(tidyverse)

set.seed(327)  

# Split data
data_split <- initial_split(mpg,
                           prop = .7)

training <- training(data_split)
testing <- testing(data_split)

# Recipe
rec <- recipe(cty ~ ., mpg) %>% 
  update_role(c(manufacturer, model),
              new_role = "evaluative")

# Fit model

mpg_fit <- 
  workflow() %>% 
  add_model(linear_reg()) %>% 
  add_recipe(rec) %>% 
  fit(training)

# Predict on all of testing 

testing %>% 
  predict(mpg_fit, new_data = .)
#> # A tibble: 71 x 1
#>    .pred
#>    <dbl>
#>  1  21.8
#>  2  18.0
#>  3  18.6
#>  4  17.0
#>  5  19.4
#>  6  16.6
#>  7  13.9
#>  8  14.2
#>  9  16.1
#> 10  11.2
#> # ... with 61 more rows

# Predict on testing without one of the "evaluative" vars

testing %>% 
  select(-manufacturer) %>% 
  predict(mpg_fit, new_data = .)
#> Error in `glubort()`:
#> ! The following required columns are missing: 'manufacturer'.

Created on 2022-04-06 by the reprex package (v2.0.1)

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.