Skip to content

The ... argument

5 messages · John Chambers, Deepayan Sarkar

#
I'm defining the following functions:
My understanding is that foo2 defined as above should
behave exactly like foo1 (and also that this sort of
usage is quite common). However, what I'm getting is:
foo1(a = F, b = list())
foo1(a = ..1, b = ..2)

However, if the values of the arguments are constants,
there appears to be no problem, e.g.:
+ b = 10, ab = FALSE)
foo1(a = temp, b = 10, ab = FALSE)
foo1(a = ..1, b = 10, ab = FALSE)

Any explanations/suggestions ?

Deepayan


__________________________________________________
Do You Yahoo!?
Get personalized email addresses from Yahoo! Mail
http://personal.mail.yahoo.com/
-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-
r-devel mailing list -- Read http://www.ci.tuwien.ac.at/~hornik/R/R-FAQ.html
Send "info", "help", or "[un]subscribe"
(in the "body", not the subject !)  To: r-devel-request@stat.math.ethz.ch
_._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._
#
Deepayan Sarkar wrote:
Well, "exactly like" is overstating it a bit.

You should get the same effect in terms of the computed results.

But the evaluator has to ensure that the usual rules of evaluation
apply.  In particular, that arguments only get evaluated when needed,
and (rather important!) only once per argument.

The semantics that does this is to imagine that variables ..1, ..2, etc.
are created in the environment of foo1 corresponding to the actual
arguments that matched ...

These arguments are what actually get passed around, ensuring that the
usual rules for evaluation are followed.  Which also explains why the
pseudo-variables aren't needed if the actual arguments are constants.

As for suggestions, you haven't said what you REALLY wanted to do, but
it sounds like you may want to do some substituting inside foo2.

By the way, this is not R-specific behavior.  It really follows from the
S language semantics, and S-Plus behaves the same way.

John

  
    
#
I think my earlier example didn't fully represent my
problem. I'm trying to evaluate the arguments passed
in via ... by:

foo1 <- function(...) {
    eval(as.list(match.call()[-1]))
}

foo2 <- function(...) foo1(...)

So now,
$a
F
$a
..1




__________________________________________________
Do You Yahoo!?
Get personalized email addresses from Yahoo! Mail
http://personal.mail.yahoo.com/
-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-
r-devel mailing list -- Read http://www.ci.tuwien.ac.at/~hornik/R/R-FAQ.html
Send "info", "help", or "[un]subscribe"
(in the "body", not the subject !)  To: r-devel-request@stat.math.ethz.ch
_._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._
#
Deepayan Sarkar wrote:
Why?

The way to get the _evaluated_ ... arguments is
  dotValues <- list(...)

See, for example, under "..." in the index to the "blue book".

  
    
#
--- John Chambers <jmc@research.bell-labs.com> wrote:
Oops! Thanks a lot, everything works fine now.



__________________________________________________
Do You Yahoo!?
Get personalized email addresses from Yahoo! Mail
http://personal.mail.yahoo.com/
-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-
r-devel mailing list -- Read http://www.ci.tuwien.ac.at/~hornik/R/R-FAQ.html
Send "info", "help", or "[un]subscribe"
(in the "body", not the subject !)  To: r-devel-request@stat.math.ethz.ch
_._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._