[Rd] problem with eval(..., parent.frame(1L)) when package is not loaded
bbolker at gmail.com
Fri Jun 28 05:49:45 CEST 2013
-----BEGIN PGP SIGNED MESSAGE-----
The lmer() function in the lme4 package has some code of the form
mc <- match.call()
mc[] <- as.name("lFormula")
lmod <- eval(mc, parent.frame(1L))
this is a fairly common idiom in R, found e.g. in lm(), used when
one wants to pass all of the arguments of a function to a different
function (in the case of lm() it's model.frame()).
This idiom fails ("error in eval(...) : could not find function
'lFormula'") when lme4 is not explicitly loaded, as will happen if one
uses lme4::lmer(...) to call the function without loading the package,
or when lmer() is called from within a function that Imports: but does
not Depend: on lme4.
A simpler version suggested by Martin Maechler shows that this is a
generic issue (except that it's unlikely to happen with base R
functions because the relevant packages _will_ be loaded unless one
bends over backwards):
R_DEFAULT_PACKAGES=NULL R --vanilla
Error in eval(expr, envir, enclos) :
could not find function "model.frame"
I wonder if anyone has encountered this and/or can think of a fix
(something with setting the enclosing environment appropriately?) The
only workarounds we can think of at present are (1) telling
dependent-package maintainers that they have to use Depends: instead
of Imports: (which seems to subvert the whole dependency-minimization
goal of Imports:) or (2) littering our code with lme4:: to make sure
that the function gets looked for in the right place (ugh).
See also https://github.com/lme4/lme4/issues/50 .
Any ideas appreciated.
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.4.10 (GNU/Linux)
Comment: Using GnuPG with undefined - http://www.enigmail.net/
-----END PGP SIGNATURE-----
More information about the R-devel