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)
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.
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 evaluatespec$engine
, which isNULL
becausenull_model()
does not accept an engine argument by default.However, one can still use
set_engine("parsnip")
on a specification withnull_model()
, which resolves the issue. It seems that sinceparsnip
is the only (currently, and likely expected) valid engine fornull_model()
, it should set this value by default to resolve the issue (or the check that fails should be able to handle aNULL
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
Created on 2024-03-19 with reprex v2.1.0