diff --git a/DESCRIPTION b/DESCRIPTION index a1b30100b..944167379 100644 --- a/DESCRIPTION +++ b/DESCRIPTION @@ -1,6 +1,6 @@ Package: parsnip Title: A Common API to Modeling and Analysis Functions -Version: 1.1.1.9003 +Version: 1.1.1.9004 Authors@R: c( person("Max", "Kuhn", , "max@posit.co", role = c("aut", "cre")), person("Davis", "Vaughan", , "davis@posit.co", role = "aut"), diff --git a/NEWS.md b/NEWS.md index a39566d52..f409d97eb 100644 --- a/NEWS.md +++ b/NEWS.md @@ -10,6 +10,9 @@ * When computing censoring weights, the resulting vectors are no longer named (#1023). +* Fixed a bug in the integration with workflows where using a model formula with a formula preprocessor could result in a double intercept (#1033). + + # parsnip 1.1.1 * Fixed bug where prediction on rank deficient `lm()` models produced `.pred_res` instead of `.pred`. (#985) diff --git a/R/convert_data.R b/R/convert_data.R index ae4d1c426..39494bb0a 100644 --- a/R/convert_data.R +++ b/R/convert_data.R @@ -45,6 +45,10 @@ rlang::abort("`composition` should be either 'data.frame' or 'matrix'.") } + if (remove_intercept) { + data <- data[, colnames(data) != "(Intercept)", drop = FALSE] + } + ## Assemble model.frame call from call arguments mf_call <- quote(model.frame(formula, data)) mf_call$na.action <- match.call()$na.action # TODO this should work better diff --git a/R/fit_helpers.R b/R/fit_helpers.R index a54557ce3..4e501db34 100644 --- a/R/fit_helpers.R +++ b/R/fit_helpers.R @@ -6,6 +6,15 @@ form_form <- function(object, control, env, ...) { + encoding_info <- + get_encoding(class(object)[1]) %>% + dplyr::filter(mode == object$mode, engine == object$engine) + + remove_intercept <- encoding_info %>% dplyr::pull(remove_intercept) + if (remove_intercept) { + env$data <- env$data[, colnames(env$data) != "(Intercept)", drop = FALSE] + } + if (inherits(env$data, "data.frame")) { check_outcome(eval_tidy(rlang::f_lhs(env$formula), env$data), object) }