Skip to content

Commit dc3bdea

Browse files
authored
allow fit_xy() for GAMs with non-mgcv engines (#1103)
1 parent 9a5e380 commit dc3bdea

File tree

2 files changed

+17
-9
lines changed

2 files changed

+17
-9
lines changed

NEWS.md

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,13 @@
11
# parsnip (development version)
22

3-
* Aligned `null_model()` with other model types; the model type now has an
4-
engine argument that defaults to `"parsnip"` and is checked with the same
5-
machinery that checks other model types in the package (#1083).
3+
4+
* `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).
5+
6+
* 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).
67

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

10+
911
# parsnip 1.2.1
1012

1113
* Added a missing `tidy()` method for survival analysis glmnet models (#1086).

R/gen_additive_mod.R

Lines changed: 12 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -94,7 +94,7 @@ translate.gen_additive_mod <- function(x, engine = x$engine, ...) {
9494
fit_xy.gen_additive_mod <- function(object, ...) {
9595
trace <- rlang::trace_back()
9696

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

107-
cli::cli_abort(c(
108-
"!" = "Please use {.fun fit} rather than {.fun fit_xy} to train \\
109-
generalized additive models.",
110-
"i" = "See {.help model_formula} to learn more."
111-
))
107+
if (identical(object$engine, "mgcv")) {
108+
cli::cli_abort(c(
109+
"!" = "Please use {.fun fit} rather than {.fun fit_xy} to train \\
110+
generalized additive models with the {.val mgcv} engine.",
111+
"i" = "See {.help model_formula} to learn more."
112+
))
113+
}
114+
115+
# allow fitting GAMs that specify smooths via other arguments to use
116+
# `fit_xy()` (#775)
117+
NextMethod()
112118
}

0 commit comments

Comments
 (0)