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(...)
"
quotes. – Serlewhat
argument todo.call
takes a character string, and I'm manipulating the value of that string – Goldado.call(getFromNamespace("rleid", "data.table"), list(c(1,1), 1:2))
Gotta break your string into its component parts, though (function, then package). – Serleget("lmer", asNamespace("lme4"))
, but I don't understand why you can't passlme4::lmer
. – RetractimportFrom(utils,unzip)
– Pinnatipeda <- "abs";
do.call(base::get(a), list(c(-1, -2)))
– Roxanneroxburgh