diff --git a/DESCRIPTION b/DESCRIPTION index d4440ebf..286cefcf 100644 --- a/DESCRIPTION +++ b/DESCRIPTION @@ -23,7 +23,7 @@ Imports: glue (>= 1.6.2), hardhat (>= 1.2.0), lifecycle (>= 1.0.1), - parsnip (>= 1.0.0), + parsnip (>= 1.0.1.9000), rlang (>= 1.0.3), tidyselect (>= 1.1.2), vctrs (>= 0.4.1) @@ -45,6 +45,8 @@ Config/Needs/website: tidyr, tidyverse/tidytemplate, yardstick +Remotes: + tidymodels/parsnip Config/testthat/edition: 3 Encoding: UTF-8 Roxygen: list(markdown = TRUE) diff --git a/R/fit-action-model.R b/R/fit-action-model.R index 4465afbc..d87016e6 100644 --- a/R/fit-action-model.R +++ b/R/fit-action-model.R @@ -190,5 +190,13 @@ new_action_model <- function(spec, formula, ..., call = caller_env()) { abort("`formula` must be a formula, or `NULL`.", call = call) } + if (!parsnip::spec_is_loaded(spec = spec)) { + parsnip::prompt_missing_implementation( + spec = spec, + prompt = cli::cli_abort, + call = call + ) + } + new_action_fit(spec = spec, formula = formula, subclass = "action_model") } diff --git a/tests/testthat/_snaps/fit-action-model.md b/tests/testthat/_snaps/fit-action-model.md index 338d8d91..ad5d41cb 100644 --- a/tests/testthat/_snaps/fit-action-model.md +++ b/tests/testthat/_snaps/fit-action-model.md @@ -15,6 +15,26 @@ ! `spec` must have a known mode. i Set the mode of `spec` by using `parsnip::set_mode()` or by setting the mode directly in the parsnip specification function. +# prompt on spec without a loaded implementation (#174) + + Code + add_model(workflow, mod) + Condition + Error in `add_model()`: + ! parsnip could not locate an implementation for `bag_tree` regression model specifications. + i The parsnip extension package baguette implements support for this specification. + i Please install (if needed) and load to continue. + +--- + + Code + workflow(spec = mod) + Condition + Error in `add_model()`: + ! parsnip could not locate an implementation for `bag_tree` regression model specifications. + i The parsnip extension package baguette implements support for this specification. + i Please install (if needed) and load to continue. + # cannot add two models Code diff --git a/tests/testthat/test-fit-action-model.R b/tests/testthat/test-fit-action-model.R index 4590c72c..c87543ac 100644 --- a/tests/testthat/test-fit-action-model.R +++ b/tests/testthat/test-fit-action-model.R @@ -22,6 +22,16 @@ test_that("model must contain a known mode (#160)", { }) }) +test_that("prompt on spec without a loaded implementation (#174)", { + mod <- parsnip::bag_tree() %>% + parsnip::set_mode("regression") + + workflow <- workflow() + + expect_snapshot(error = TRUE, add_model(workflow, mod)) + expect_snapshot(error = TRUE, workflow(spec = mod)) +}) + test_that("cannot add two models", { mod <- parsnip::linear_reg() mod <- parsnip::set_engine(mod, "lm")