[R] Arguments macthing

Stephane DRAY stephane.dray at umontreal.ca
Fri Nov 26 22:30:42 CET 2004


Hello list,
I have a question concerning argument matching I have read R Language 
Definition before).
I have a function multxby2 which takes as argument the call to another 
function f1.
I would like to take the values of xx from the call to f1 and use it in 
multxby2.

Here is an example:


multxby2 <- function(callf) {
     appel1<-match.call()
     appel<-as.list(as.call(appel1$callf))

     px<-pmatch(names(appel),"xx")

     if(sum(is.na(px))!=length(appel)) print(appel[[which(!is.na(px))]]*2)
     # else ...

}

f1=function(xx=2,y=3){}

multxby2(f1(x=3))

My problem is due to the various ways that a user can enter its arguments, 
how to be sure to get xx from various call such as:

multxby2(f1(3,2))
multxby2(f1(y=2,3))

Is there a way to do that avoiding a lot of "if" and how to solve the last 
case ? My practical case takes functions with around 20 arguments.

Thanks in advance,

Sincerely.
Stéphane DRAY
-------------------------------------------------------------------------------------------------- 

Département des Sciences Biologiques
Université de Montréal, C.P. 6128, succursale centre-ville
Montréal, Québec H3C 3J7, Canada

Tel : (514) 343-6111 poste 1233         Fax : (514) 343-2293
E-mail : stephane.dray at umontreal.ca
-------------------------------------------------------------------------------------------------- 

Web                                          http://www.steph280.freesurf.fr/




More information about the R-help mailing list