I want to do.call
an (exported) function from a package and need to specify the package and function in the what
argument as a character string (i.e., when the package is not loaded into my environment or there is a potential function name conflict).
The function name is a character string like "lme4::lmer"
which specifies both the package and the function.
For example, to conditionally call a function (similar to this question):
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"
Other ways work but are not what I need:
# Load the package and use only the function string
library(lme4)
do.call("lmer", ...)
# Or calling the function directly:
lme4::lmer(...)