Skip to content

repair_call() uninformative error when x isn't a parsnip model #598

@EmilHvitfeldt

Description

@EmilHvitfeldt

The documentation for repair_call() says that x should be "A fitted parsnip model." But if you didn't see that (like I did) it produces errors when applied to non-parsnip fits.

I have two thoughts

  1. Have repair_call() explicitly check if x is of class model_fit and error accordingly.
  2. Expand the use of repair_call() to work with workflow objects, and possibly the raw engine fit.

Right now it is a little awkward because you need to call two extract_fit_*() functions

wf_fit %>%
  extract_fit_parsnip() %>%
  repair_call(mtcars) %>%
  extract_fit_engine()
library(tidymodels)

lm_spec <- linear_reg() %>%
  set_mode("regression") %>%
  set_engine("lm")

lm_wf <- workflow() %>% 
    add_formula(mpg ~ .) %>% 
  add_model(lm_spec)

wf_fit <- fit(lm_wf, data = mtcars)
parsnip_fit <- extract_fit_parsnip(wf_fit)
engine_fit <- extract_fit_engine(wf_fit)

repair_call(parsnip_fit, mtcars)
#> parsnip model object
#> 
#> Fit time:  4ms 
#> 
#> Call:
#> stats::lm(formula = ..y ~ ., data = mtcars)
#> 
#> Coefficients:
#> (Intercept)          cyl         disp           hp         drat           wt  
#>    12.30337     -0.11144      0.01334     -0.02148      0.78711     -3.71530  
#>        qsec           vs           am         gear         carb  
#>     0.82104      0.31776      2.52023      0.65541     -0.19942
repair_call(wf_fit, mtcars)
#> Error: No `call` object to modify.
repair_call(engine_fit, mtcars)
#> Error: No `call` object to modify.

Created on 2021-11-12 by the reprex package (v2.0.1)

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugan unexpected problem or unintended behavior

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions