[R] Arguments of a function

Mathieu Ros mros at toulouse.inra.fr
Fri Aug 2 17:36:52 CEST 2002


>>>>> "FB" == Florent BATY <baty at biomserv.univ-lyon1.fr> disait:

    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()...

-- 
Mathieu Ros 
Laboratoire de Génétique Cellulaire, INRA Toulouse 

-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-
r-help 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-help-request at stat.math.ethz.ch
_._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._



More information about the R-help mailing list