I have never had issues with rlang::exec
, but it mysteriously seems to fail with WRS2::rmmcp
and I am not sure why or how to solve it.
# setup
set.seed(123)
library(WRS2)
library(rlang)
# works
WRS2::rmmcp(
y = WineTasting$Taste,
groups = WineTasting$Wine,
blocks = WineTasting$Taster
)
#> Call:
#> WRS2::rmmcp(y = WineTasting$Taste, groups = WineTasting$Wine,
#> blocks = WineTasting$Taster)
#>
#> psihat ci.lower ci.upper p.value p.crit sig
#> Wine A vs. Wine B 0.02143 -0.02164 0.06449 0.19500 0.0500 FALSE
#> Wine A vs. Wine C 0.11429 0.02148 0.20710 0.00492 0.0169 TRUE
#> Wine B vs. Wine C 0.08214 0.00891 0.15538 0.00878 0.0250 TRUE
# doesn't work
rlang::exec(
.fn = WRS2::rmmcp,
y = WineTasting$Taste,
groups = WineTasting$Wine,
blocks = WineTasting$Taster
)
#> Error in names(x) <- value: 'names' attribute [18] must be the same length as the vector [3]
Why does this fail and how to solve it?
One alternative to exec
is to construct the call by hand and then evaluate it:
mycall <- rlang::call2( "rmmcp", .ns="WRS2",
y = quote(WineTasting$Taste),
groups = quote(WineTasting$Wine),
blocks = quote(WineTasting$Taster) )
# WRS2::rmmcp(y = WineTasting$Taste, groups = WineTasting$Wine,
# blocks = WineTasting$Taster)
eval(mycall) # Works