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: f1<-function(x,y,...){ ? print(x) } f2<-function(...){ ? f1(...) } f2(1,2,3) In the call above how are the three numbers bound to the individual formal arguments x and y of f1 rather than f1 being called with a single pairlist, which is what the documentation says ... is. 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 Jyotirmoy Bhattacharya
It likely has to do with the fact that barchart uses unevaluated arguments. Look at its source by entering its name without arguments: barchart This does work: library(lattice) f.barchart2 <- function(...) eval.parent(substitute(barchart(...))) x <- data.frame(a = c(1,1,2,2), b = c(1,2,3,4), d = c(1,2,2,1)) print(f.barchart2(a ~ b, data = x, groups = d)) On Fri, Feb 19, 2010 at 6:25 AM, Jyotirmoy Bhattacharya <jmoy.matecon at gmail.com> 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: > > f1<-function(x,y,...){ > ? print(x) > } > > f2<-function(...){ > ? f1(...) > } > > f2(1,2,3) > > In the call above how are the three numbers bound to the individual > formal arguments x and y of f1 rather than f1 being called with a > single pairlist, which is what the documentation says ... is. > > 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 > > Jyotirmoy Bhattacharya > > ______________________________________________ > R-help at r-project.org mailing list > https://stat.ethz.ch/mailman/listinfo/r-help > PLEASE do read the posting guide http://www.R-project.org/posting-guide.html > and provide commented, minimal, self-contained, reproducible code. >
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: > > f1<-function(x,y,...){ > print(x) > } >it would print(x), probably complain that y is missing> f2<-function(...){ > f1(...) > } > > f2(1,2,3) >Hi! print the .. and see what happens: f2<-function(...){ f1(...) print(list(...)) } f2(1,2,3)> In the call above how are the three numbers bound to the individual > formal arguments x and y of f1 rather than f1 being called with a > single pairlist, which is what the documentation says ... is. > > 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. cheers, Paul> Jyotirmoy Bhattacharya > > ______________________________________________ > R-help at r-project.org mailing list > https://stat.ethz.ch/mailman/listinfo/r-help > PLEASE do read the posting guide http://www.R-project.org/posting-guide.html > and provide commented, minimal, self-contained, reproducible code. >-- Drs. Paul Hiemstra Department of Physical Geography Faculty of Geosciences University of Utrecht Heidelberglaan 2 P.O. Box 80.115 3508 TC Utrecht Phone: +3130 274 3113 Mon-Tue Phone: +3130 253 5773 Wed-Fri http://intamap.geo.uu.nl/~paul
> 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).You might also be interested in other thread regarding this problem: http://groups.google.com/group/r-help-archive/msg/5c6ea5eb593337b4 Regards Tom