[R] dot-dot-dot as an actual argument

Deepayan Sarkar deepayan.sarkar at gmail.com
Sat Feb 20 06:25:46 CET 2010


On Fri, Feb 19, 2010 at 4:44 AM, Paul Hiemstra <p.hiemstra at geo.uu.nl> wrote:
> Jyotirmoy Bhattacharya wrote:
>>
>> I could not find any documentation of how dot-dot-dot works when used
>> as an argument in a function call (rather than as a formal argument in
>> a definition). I would appreciate some references to the rules
>> governing situations like:

[...]

>> And while the example above succeeds, why does the following fail,
>>
>> library(lattice)
>> f.barchart <- function(...) {
>>    barchart(...)
>> }
>>
>> x <- data.frame(a = c(1,1,2,2), b = c(1,2,3,4), d = c(1,2,2,1))
>> print(f.barchart(a ~ b, data = x, groups = d))
>>
>> This gives the error:
>> Error in eval(expr, envir, enclos) :
>>  ..3 used in an incorrect context, no ... to look in
>>
>
> The problem is that d is a column in x and not a seperate R object. This is
> solved in barchart because the function knows that it needs to look in x for
> d. The problem only is that when the third (group = d) is taken from the ...
> (..3) it doesn't find any R object called d. So it crashes with the above
> error.

Yes, and to reinforce the point that ... is not the issue here:

> f.barchart <- function(x, data, groups) {
+     barchart(x, data = data, groups = groups)
+ }
> x <- data.frame(a = c(1,1,2,2), b = c(1,2,3,4), d = c(1,2,2,1))
> print(f.barchart(a ~ b, data = x, groups = d))
Error in eval(expr, envir, enclos) : object 'groups' not found

-Deepayan



More information about the R-help mailing list