This question is a follow-up to a previous answer which raised a puzzle.
Reproducible example from the previous answer:
Models <- list( lm(runif(10)~rnorm(10)),lm(runif(10)~rnorm(10)),lm(runif(10)~rnorm(10)) )
lm1 <- lm(runif(10)~rnorm(10))
library(functional)
# This works
do.call( Curry(anova, object=lm1), Models )
# But so does this
do.call( anova, Models )
The question is why does do.call(anova, Models)
work fine, as @Roland points out?
The signature for anova is anova(object, ...)
anova
calls UseMethod
, which should* call anova.lm
which should call anova.lmlist
, whose first line is objects <- list(object, ...)
, but object
doesn't exist in that formulation.
The only thing I can surmise is that do.call
might not just fill in ellipses but fills in all arguments without defaults and leaves any extra for the ellipsis to catch? If so, where is that documented, as it's definitely new to me!
* Which is itself a clue--how does UseMethod
know to call anova.lm
if the first argument is unspecified? There's no anova.list
method or anova.default
or similar...
do.call(plot, list(1:2, 1:2, col="red"))
? It seems to obey the standard behaviour re positional matching, named arguments and...
. – Footworndo.call(anova, Models)
being the same asanova(Models[[1]], Models[[2]], Models[[3]])
? – Rosiodo.call
is always talked about as a solution to...
, I guess it's never mentioned that it will also fill in according to the positional matching rules. But this was pretty surprising to me. – Uncledo.call
just does a basic lexical substitution fromdo.call(f, list(...))
tof(...)
- and you can always pass both named and unnamed arguments along to ... – Draughtsf(...)
" is similar to what I've read in other places, and is what led me to believe that it substitutes for...
rather than following the usual positional, naming, unnamed rules. – Uncledo.call
works – Draughts