Skip to content

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

Description

@wzbillings

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

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

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