From deepayan.sarkar at gmail.com  Tue Aug 21 07:20:33 2007
From: deepayan.sarkar at gmail.com (deepayan.sarkar at gmail.com)
Date: Mon, 20 Aug 2007 22:20:33 -0700
Subject: [Rd] aesthetics of do.call
In-Reply-To: <Pine.GSO.4.58.0708202348040.26109@capecod.bwh.harvard.edu>
References: <Pine.GSO.4.58.0708202348040.26109@capecod.bwh.harvard.edu>
Message-ID: <eb555e660708202220k2cce4d05y416998945d7659da@mail.gmail.com>

On 8/20/07, Vincent Carey 525-2265 <stvjc at channing.harvard.edu> wrote:
>
>
> library(MASS)
> G1 = glm(sp~CW, data=crabs, fam=binomial)
> G2 = do.call("glm", list(sp~CW, family=binomial, data=crabs))
>
> G1$call is very nice to look at
> G2$call is very voluminous
>
> if we revise do.call to
>
> function (what, args, quote = FALSE, envir = parent.frame())
> {
>     if (!is.list(args))
>         stop("second argument must be a list")
>     if (quote) {
>         enquote <- function(x) as.call(list(as.name("quote"),
>             x))
>         args <- lapply(args, enquote)
>     }
>     ans = .Internal(do.call(what, args, envir))
>     ans$call = match.call()
>     ans
> }
>
> G1 and G2 look a lot more alike

But then you get things like

> do.call(c, list(1, 2, 3))
[[1]]
[1] 1

[[2]]
[1] 2

[[3]]
[1] 3

$call
do.call2(what = c, args = list(1, 2, 3))

Warning message:
In ans$call = match.call() : Coercing LHS to a list

which is probably not what you want to happen.

-Deepayan



[Rd] aesthetics of do.call
deepayan.sarkar at gmail.com