Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion DESCRIPTION
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand All @@ -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)
Expand Down
8 changes: 8 additions & 0 deletions R/fit-action-model.R
Original file line number Diff line number Diff line change
Expand Up @@ -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")
}
20 changes: 20 additions & 0 deletions tests/testthat/_snaps/fit-action-model.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
10 changes: 10 additions & 0 deletions tests/testthat/test-fit-action-model.R
Original file line number Diff line number Diff line change
Expand Up @@ -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")
Expand Down