Skip to content
Prev 22335 / 398502 Next

Arguments of a function

FB> Hello, Is it possible to call a function having x arguments
    FB> with vector containing the x values of the arguments in it ?
    FB> To make myself clearer, I was wandering if from a function f:

    >> f
    FB>     function(a,b) a+b

    FB> and a vector v which the 2 values of the arguments "a" and
    FB> "b":

    >> v
    FB>     a b 1 2
    >> names(v)
    FB>     [1] "a" "b"

    FB> it is possible to call the function f with vector v as the
    FB> arguments of the function.  If I use f(v) it returns me an
    FB> error since v was considered as the value of the first
    FB> argument.

    FB> Do you any ideas ??

f<-function(x,y){
    if (is.list(x)) {
        y <- x$y
        x <- x$x
    }
    x+y
}

should work.
or look at the code of legend()...