Become an expert in R — Interactive courses, Cheat Sheets, certificates and more!
Get Started for Free

repair_call

Repair a model call object


Description

When the user passes a formula to fit() and the underlying model function uses a formula, the call object produced by fit() may not be usable by other functions. For example, some arguments may still be quosures and the data portion of the call will not correspond to the original data.

Usage

repair_call(x, data)

Arguments

x

A fitted parsnip model. An error will occur if the underlying model does not have a call element.

data

A data object that is relavant to the call. In most cases, this is the data frame that was given to parsnip for the model fit (i.e., the training set data). The name of this data object is inserted into the call.

Details

repair_call() call can adjust the model objects call to be usable by other functions and methods.

Value

A modified parsnip fitted model.

Examples

fitted_model <-
  linear_reg() %>%
  set_engine("lm", model = TRUE) %>%
  fit(mpg ~ ., data = mtcars)

# In this call, note that `data` is not `mtcars` and the `model = ~TRUE`
# indicates that the `model` argument is an `rlang` quosure.
fitted_model$fit$call

# All better:
repair_call(fitted_model, mtcars)$fit$call

parsnip

A Common API to Modeling and Analysis Functions

v0.1.5
GPL-2
Authors
Max Kuhn [aut, cre], Davis Vaughan [aut], RStudio [cph]
Initial release

We don't support your browser anymore

Please choose more modern alternatives, such as Google Chrome or Mozilla Firefox.