Skip to content

re-implement missing extension error on add_model #184

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 5 commits into from
Nov 14, 2022
Merged
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
2 changes: 1 addition & 1 deletion DESCRIPTION
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ Imports:
hardhat (>= 1.2.0),
lifecycle (>= 1.0.3),
modelenv (>= 0.1.0),
parsnip (>= 1.0.0),
parsnip (>= 1.0.3),
rlang (>= 1.0.3),
tidyselect (>= 1.2.0),
vctrs (>= 0.4.1)
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