[R] protecting "..."
Duncan Murdoch
murdoch at stats.uwo.ca
Sun Nov 18 12:19:19 CET 2007
Johannes Hüsing wrote:
> Duncan Murdoch <murdoch at stats.uwo.ca> [Sat, Nov 17, 2007 at 11:56:52PM CET]:
>
>> On 17/11/2007 5:04 PM, Johannes Hüsing wrote:
>>
>>> I just realized that the "..." argument in a function cannot be used
>>> without
>>> taking precautions sometimes. The following behaviour is what I
>>> stumbled upon:
>>>
>> The problem is the way replicate is implemented. It takes the
>> expression, and wraps it in a function(...) before calling sapply. The
>> ... in your expression matches the ... in the wrapper function, not the
>> ... from the parent.
>>
>
> Many thanks! Pose a question, go to sleep, wake up, read the answer.
> I feel like being in old Cologne
> (http://en.wikipedia.org/wiki/Heinzelm%C3%A4nnchen).
>
>
>
>> I think you'll need to make calls to sapply directly to do what you
>> want.
>>
>>
>
> Do you mean to replace "replicate" by the contents of the function?
> I am feeling more comfortable with my solution.
What I meant was something like this:
myrepl2 <- function(length, fun, ...) {
iterfun <- function(n) fun(...)
sapply(integer(length), iterfun)
}
but your solution works too.
Duncan Murdoch
More information about the R-help
mailing list