Skip to content

Commit

Permalink
allow fit_xy() for GAMs with non-mgcv engines (#1103)
Browse files Browse the repository at this point in the history
  • Loading branch information
simonpcouch authored Jul 14, 2024
1 parent 9a5e380 commit dc3bdea
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 9 deletions.
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()
}

0 comments on commit dc3bdea

Please sign in to comment.