tidymodels / parsnip

A tidy unified interface to models
https://parsnip.tidymodels.org
Other
599 stars 89 forks source link

`null_model()` requires the engine to be set in some cases, but doesn't allow an engine argument #1083

Closed wzbillings closed 7 months ago

wzbillings commented 8 months ago

The problem

If you try to fit a null_model() model specification, R returns an error about the engine argument, presumably because it tries to evaluate spec$engine, which is NULL because null_model() does not accept an engine argument by default.

However, one can still use set_engine("parsnip") on a specification with null_model(), which resolves the issue. It seems that since parsnip is the only (currently, and likely expected) valid engine for null_model(), it should set this value by default to resolve the issue (or the check that fails should be able to handle a NULL engine argument).

If this behavior is intentional, I think the error message should be more informative, but it seems like it would be useful to specify an engine argument with parsnip as the default.

Reproducible example

library(parsnip)
data(mtcars)

null_mod <- parsnip::null_model(mode = "regression")
null_fit <- null_mod |> parsnip::fit(mpg ~ wt, data = mtcars)
#> Error in if (is.null(x) | spec$engine == "spark") {: argument is of length zero

null_mod2 <- parsnip::null_model(mode = "regression") |>
    parsnip::set_engine("parsnip")
null_fit2 <- null_mod2 |> parsnip::fit(mpg ~ wt, data = mtcars)

Created on 2024-03-19 with reprex v2.1.0

github-actions[bot] commented 7 months ago

This issue has been automatically locked. If you believe you have found a related problem, please file a new issue (with a reprex: https://reprex.tidyverse.org) and link to this issue.