From e479ba04ae1b65fe8bb66d7c7c9109a146eda53e Mon Sep 17 00:00:00 2001 From: Hannah Frick Date: Fri, 1 Dec 2023 20:21:26 +0000 Subject: [PATCH 1/3] for intercepts coming from workflows (details in the PR description) --- R/convert_data.R | 4 ++++ R/fit_helpers.R | 9 +++++++++ 2 files changed, 13 insertions(+) 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) } From c16628119542bb71867503b01d54a8857784480a Mon Sep 17 00:00:00 2001 From: Hannah Frick Date: Fri, 1 Dec 2023 20:21:44 +0000 Subject: [PATCH 2/3] bump version for extratests --- DESCRIPTION | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) 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"), From b54dcd1bf38001395f017847149386262f0b01f6 Mon Sep 17 00:00:00 2001 From: Hannah Frick Date: Fri, 1 Dec 2023 20:56:18 +0000 Subject: [PATCH 3/3] update NEWS --- NEWS.md | 3 +++ 1 file changed, 3 insertions(+) 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)