[R] Can you recover default argument values of a function?

From: Talbot Katz <topkatz_at_msn.com>
Date: Wed, 26 Dec 2007 16:42:46 -0500


Maybe this is a stupid question. If so, I apologize, but here goes. Suppose I have a function f1(x,...) that calls a function f2(y1,y2,...,yn) in the following way: if x satisfies a certain condition, then I want to call f2(x,y2,...,yn); otherwise I want to use the default value of y1, if there is one. I could do something like the following:  

v <- ifelse ( is.null(x), f2( , y2,..., yn), f2( x, y2,..., yn) )  

but I'm doing this in a loop (where the y2,...,yn variables may change), and I'd prefer not to execute the ifelse statement each time, so I'd like an initial pre-loop ifelse such as the following:  

y0 <- ifelse ( is.null(x), default(y1), x )  

where default(y1) is the default value of the y1 argument of f2. Then, inside the loop I'd have  

v <- f2( y0, y2,..., yn )  

Is there any mechanism that tells me how many arguments a function has, and the default values of each one, if there are default values?  


R-help_at_r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code. Received on Wed 26 Dec 2007 - 21:50:15 GMT

Archive maintained by Robert King, hosted by the discipline of statistics at the University of Newcastle, Australia.
Archive generated by hypermail 2.2.0, at Wed 26 Dec 2007 - 23:30:20 GMT.

Mailing list information is available at https://stat.ethz.ch/mailman/listinfo/r-help. Please read the posting guide before posting to the list.