[R] how can a function tell if defaults are used?
Robin Hankin
r.hankin at auckland.ac.nz
Mon Apr 22 06:14:53 CEST 2002
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
_._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._
More information about the R-help
mailing list