Skip to content

allow fit_xy() for GAMs with non-mgcv engines #1103

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 2 commits into from
Jul 14, 2024
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
8 changes: 5 additions & 3 deletions NEWS.md
Original file line number Diff line number Diff line change
@@ -1,11 +1,13 @@
# parsnip (development version)

* Aligned `null_model()` with other model types; the model type now has an
engine argument that defaults to `"parsnip"` and is checked with the same
machinery that checks other model types in the package (#1083).

* `fit_xy()` currently raises an error for `gen_additive_mod()` model specifications as the default engine (`"mgcv"`) specifies smoothing terms in model formulas. However, some engines specify smooths via additional arguments, in which case the restriction on `fit_xy()` is excessive. parsnip will now only raise an error when fitting a `gen_additive_mod()` with `fit_xy()` when using the `"mgcv"` engine (#775).

* Aligned `null_model()` with other model types; the model type now has an engine argument that defaults to `"parsnip"` and is checked with the same machinery that checks other model types in the package (#1083).

* New `extract_fit_time()` method has been added that returns the time it took to train the model (#853).


# parsnip 1.2.1

* Added a missing `tidy()` method for survival analysis glmnet models (#1086).
Expand Down
18 changes: 12 additions & 6 deletions R/gen_additive_mod.R
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,7 @@ translate.gen_additive_mod <- function(x, engine = x$engine, ...) {
fit_xy.gen_additive_mod <- function(object, ...) {
trace <- rlang::trace_back()

if ("workflows" %in% trace$namespace) {
if ("workflows" %in% trace$namespace & identical(object$engine, "mgcv")) {
cli::cli_abort(
c("!" = "When working with generalized additive models, please supply the
model specification to {.fun workflows::add_model} along with a \\
Expand All @@ -104,9 +104,15 @@ fit_xy.gen_additive_mod <- function(object, ...) {
)
}

cli::cli_abort(c(
"!" = "Please use {.fun fit} rather than {.fun fit_xy} to train \\
generalized additive models.",
"i" = "See {.help model_formula} to learn more."
))
if (identical(object$engine, "mgcv")) {
cli::cli_abort(c(
"!" = "Please use {.fun fit} rather than {.fun fit_xy} to train \\
generalized additive models with the {.val mgcv} engine.",
"i" = "See {.help model_formula} to learn more."
))
}

# allow fitting GAMs that specify smooths via other arguments to use
# `fit_xy()` (#775)
NextMethod()
}
Loading