[R] how can a function tell if defaults are used?
Roger Peng
rpeng at stat.ucla.edu
Mon Apr 22 07:04:46 CEST 2002
Maybe a better way is:
e <- function(first, second) {
if(missing(second))
return(c(Re(first), Im(first)))
else
return(c(Re(first), Re(second)))
}
I'm not sure if this is what you're going for.
-roger
_______________________________
UCLA Department of Statistics
rpeng at stat.ucla.edu
http://www.stat.ucla.edu/~rpeng
On Mon, 22 Apr 2002, Robin Hankin wrote:
>
> Hello everybody
>
>
> Is there a good way for a function to tell whether the caller used the
> defaults?
>
> I'm writing a little function that may take a pair of real arguments
> or a single complex argument (in which case I want the real and
> imaginary components).
>
>
> "e" <- function(first,second=first) {
> if (all(first == second) & is.complex(first)) {
> return(c(Re(first),Im(first)))
> } else {
> return (c(Re(first),Re(second)))
> }
> }
>
>
> Thus
>
> > e(1+5i)
> [1] 1 5
> > e(1,5)
> [1] 1 5
>
>
> which is what I want, but what is the best way to test whether the
> second argument is explicitly set by the caller or the default is
> used? My only idea was to test for first == second but this can't be
> optimal. Help anyone?
>
>
> --
>
> Robin Hankin, Lecturer,
> School of Geographical and Environmental Science
> Private Bag 92019 Auckland
> New Zealand
>
> r.hankin at auckland.ac.nz
> tel 0064-9-373-7599 x6820; FAX 0064-9-373-7042
>
> -.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-
> 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
> _._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._
>
-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-
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