Skip to content
Prev 304597 / 398503 Next

How to modify the values of the parameters passing via ...

Hello,

You could see what is fun1 receiving with this modification meant for 
debugging:

fun1 <-function(x, y, z=10){
     print(match.call())
     x + y + z
}

Anyway, there is s standard way of dealing with argument '...' when one 
needs to know what was passed.
Include dots <- list(...) at the beginning of fun2 and then use it when 
necessary:

fun1 <-function(x, y, z=10){x + y + z}

fun2 <-function(aa, ...) {
   dots <- list(...)
   a <- fun1(x=aa, y=5)    # works well  a=1+5+10=16
   b <- fun1(x=aa, ...)    # works well  b=1+4+8=13
   y <- 0                  # it will not affect values passed using ...
   c <- fun1(x=aa, ...)    # works well but c = 1+4+8=13
   d <- fun1(x=aa, y=5, dots$z)  # works well  d=1+5+8=14
   c(a, b, c, d)
}

fun2(aa=1, y=4, z=8)
[1] 16 13 13 14


Also, to end statements with ';' is a C language tique, R doesn't need it.
(Nor it hurts.)

Hope this helps,

Rui Barradas

Em 30-08-2012 23:07, Zhiqiu Hu escreveu: