Conversation
Member
|
I think that {embed} is the right place for this. i'll try to look at this later this week! |
Author
|
This step can also be used for causal inference - and since it can be used with any other previous steps, it can also adjust non-linear terms. Here's a very simple example: library(embed)
#> Loading required package: recipes
#> Loading required package: dplyr
#>
#> Attaching package: 'dplyr'
#> The following objects are masked from 'package:stats':
#>
#> filter, lag
#> The following objects are masked from 'package:base':
#>
#> intersect, setdiff, setequal, union
#>
#> Attaching package: 'recipes'
#> The following object is masked from 'package:stats':
#>
#> step
n <- 500
set.seed(333)
dat <- tibble(
Z = rnorm(n),
X = 3^Z + 1.3 * Z^2 - rnorm(n),
Y = 30 * Z - 4 * X + 100 * rnorm(n)
)
plot(dat)rec <- recipe(Y ~ ., data = dat) |>
step_spline_b(Z, deg_free = 5) |>
step_adjust_linear(X, remove_vars = vars(starts_with("Z")))
baked <- prep(rec) |> bake(new_data = dat, stop_at = 2)
lm(Y ~ X, data = dat) # confounded
#>
#> Call:
#> lm(formula = Y ~ X, data = dat)
#>
#> Coefficients:
#> (Intercept) X
#> -6.202 -0.587
lm(Y ~ X, data = baked) # should be about ~4
#>
#> Call:
#> lm(formula = Y ~ X, data = baked)
#>
#> Coefficients:
#> (Intercept) X
#> 2.070 -3.199Created on 2026-09-23 with reprex v2.1.1 |
1 task
The example adds a data frame to a ggplot object via `+`, which is only supported by the S7-based ggplot2 (>= 4.0.0). On oldrel-4 CI, an older ggplot2 is resolved and the example errors during R CMD check.
…mple p + baked_df relies on fragile S3/S7 Ops dispatch (ggplot2 issue #6811): it works on some R/pkg combinations but throws "Incompatible methods (Ops.S7_object, Ops.data.frame)" and errors on others (e.g. oldrel-4 CI), even with identical package versions installed. Use ggplot2::ggplot_add() instead, which is the supported, non-operator way to swap a plot's data and isn't subject to that dispatch conflict.
This branch has not been deployed
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.

This PR addresses the feature request in #275.
I have named the step
step_adjust_linear()- its functionality can be seen in the original issue.Here is the example from the docs:
Created on 2026-09-23 with reprex v2.1.1
Since the step does not depend on any package other than
statsI'm not sure if{embed}or{recipes}are the right place for it.