我想要do.call
一个包中的(导出的)函数,并且需要在what
参数中将包和函数指定为字符串(即,当包未加载到我的环境中或存在潜在的函数名称冲突时)。
"lme4::lmer"
函数名是指定包和函数的字符串。
例如,有条件地调用一个函数(类似于这个问题):
FUN = if(TRUE) {
"lme4::lmer"
} else {
"nlme::nmle"
}
args.list = list(Reaction ~ Days + (Days | Subject),
quote(lme4::sleepstudy))
do.call(what=FUN, args=args.list)
# Error in `lme4::lmer`(Reaction ~ Days + (Days | Subject), lme4::sleepstudy) :
# could not find function "lme4::lmer"
其他方式有效,但不是我需要的:
# Load the package and use only the function string
library(lme4)
do.call("lmer", ...)
# Or calling the function directly:
lme4::lmer(...)