From jason at cs.jhu.edu  Wed Jan 11 12:50:23 2006
From: jason at cs.jhu.edu (jason@cs.jhu.edu)
Date: Wed, 11 Jan 2006 12:50:23 +0100 (CET)
Subject: [Rd] problem with replicate and "..." (PR#8473)
Message-ID: <20060111115023.15174206ED@slim.kubism.ku.dk>

p.s. Note that one workaround is

> bar <- function(n,...) { f <- function() foo(...); 
+                          replicate(n,f()) }
> bar(10,3)
     [,1] [,2] [,3] [,4] [,5] [,6] [,7] [,8] [,9] [,10]
[1,]    3    3    3    3    3    3    3    3    3     3
[2,]    2    2    2    2    2    2    2    2    2     2

A little while ago, Jason Eisner wrote:

> I am using R version 2.0.0 (2004-10-04) on Fedora Core 2.
>
> This works correctly:
>
>> foo <- function(x=1,y=2) { c(x,y) }
>> bar <- function(n,...) c(n,foo(...))
>> bar(10,3)
> [1] 10  3  2
>
> But it goes wrong if I replace "c" in bar with "replicate":
>
>> foo <- function(x=1,y=2) { c(x,y) }
>> bar <- function(n,...) replicate(n,foo(...))
>> bar(10,3)
>      [,1] [,2] [,3] [,4] [,5] [,6] [,7] [,8] [,9] [,10]
> [1,]    0    0    0    0    0    0    0    0    0     0
> [2,]    2    2    2    2    2    2    2    2    2     2
>
> It is mysterious why x was bound to the apparently arbitrary
> value 0 while y was left at its default.
>
> The ... arguments to bar seems to be ignored altogether.
> bar(10), bar(10,x=3), and bar(10,3,4) give the same result.
> Furthermore, bar(10,extra=3) does not give an error.
>
> Perhaps this mysterious behavior is unavoidable because of 
> the kind of hack replicate is?
>
> Thanks ...



[Rd] problem with replicate and "..." (PR#8473)
jason@cs.jhu.edu