I am trying to use rlang::exec
in custom functions where I want to pass additional arguments as a list and then splice them. Usually this works without any problem. But I am encountering problems while doing this routine when there is a formula
argument involved.
without list
library(rlang)
exec(
.fn = stats::t.test,
formula = wt ~ am,
data = mtcars
)
#>
#> Welch Two Sample t-test
#>
#> data: wt by am
#> t = 5.4939, df = 29.234, p-value = 6.272e-06
#> alternative hypothesis: true difference in means between group 0 and group 1 is not equal to 0
#> 95 percent confidence interval:
#> 0.8525632 1.8632262
#> sample estimates:
#> mean in group 0 mean in group 1
#> 3.768895 2.411000
with list
extra.args <- list(formula = wt ~ am)
exec(
.fn = stats::t.test,
data = mtcars,
!!!extra.args
)
#> Error in t.test.default(data = structure(list(mpg = c(21, 21, 22.8, 21.4, : argument "x" is missing, with no default
How can I get this to work?
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…