Skip to content

Commit 0372970

Browse files
authored
Remove intercept coming from workflows based on engine encodings (#1033)
* for intercepts coming from workflows (details in the PR description) * bump version for extratests * update NEWS
1 parent d65dde2 commit 0372970

File tree

4 files changed

+17
-1
lines changed

4 files changed

+17
-1
lines changed

DESCRIPTION

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
Package: parsnip
22
Title: A Common API to Modeling and Analysis Functions
3-
Version: 1.1.1.9003
3+
Version: 1.1.1.9004
44
Authors@R: c(
55
person("Max", "Kuhn", , "max@posit.co", role = c("aut", "cre")),
66
person("Davis", "Vaughan", , "davis@posit.co", role = "aut"),

NEWS.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,9 @@
1010

1111
* When computing censoring weights, the resulting vectors are no longer named (#1023).
1212

13+
* Fixed a bug in the integration with workflows where using a model formula with a formula preprocessor could result in a double intercept (#1033).
14+
15+
1316
# parsnip 1.1.1
1417

1518
* Fixed bug where prediction on rank deficient `lm()` models produced `.pred_res` instead of `.pred`. (#985)

R/convert_data.R

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,10 @@
4545
rlang::abort("`composition` should be either 'data.frame' or 'matrix'.")
4646
}
4747

48+
if (remove_intercept) {
49+
data <- data[, colnames(data) != "(Intercept)", drop = FALSE]
50+
}
51+
4852
## Assemble model.frame call from call arguments
4953
mf_call <- quote(model.frame(formula, data))
5054
mf_call$na.action <- match.call()$na.action # TODO this should work better

R/fit_helpers.R

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,15 @@
66
form_form <-
77
function(object, control, env, ...) {
88

9+
encoding_info <-
10+
get_encoding(class(object)[1]) %>%
11+
dplyr::filter(mode == object$mode, engine == object$engine)
12+
13+
remove_intercept <- encoding_info %>% dplyr::pull(remove_intercept)
14+
if (remove_intercept) {
15+
env$data <- env$data[, colnames(env$data) != "(Intercept)", drop = FALSE]
16+
}
17+
918
if (inherits(env$data, "data.frame")) {
1019
check_outcome(eval_tidy(rlang::f_lhs(env$formula), env$data), object)
1120
}

0 commit comments

Comments
 (0)