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@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

______________________________________________
R-help@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.

Reply via email to