[R] R function writing question
Thomas Lumley
thomas at biostat.washington.edu
Fri Sep 8 01:51:24 CEST 2000
On Fri, 8 Sep 2000, Rachel Merriman wrote:
> Hi there!
> I'm looking for a better way of getting the following code working --
> can you help? Instead of having to type in:
>
> binarymissing(y ~ x1 + x2,data=mydata,na.action=na.keep)
>
> as my function call, I would prefer not having to type in
> na.action=na.keep each time as this will always be the same.
options(na.action=na.keep)
will set the global default na.action.
Alternatively add the line
if(is.null(mf$na.action)) mf$na.action=as.name("na.keep")
after mf<-match.call()
[or more generally
if(is.null(mf$na.action)) mf$na.action==formals(binarymissing)$na.action
which will fill in the actual default value]
The reason that the obvious approach doesn't work is that
match.call() returns the call that was actually typed, which has no
na.action argument. This is then turned into a model.frame call with no
na.action argument, which means that the default
for model.frame, ie getOption("na.action"), is used. It's not
completely clear whether this is a bug.
One interesting question is whether we should have an option to
match.call() that fills in defaults by looking at formals(call[[1]]).
-thomas
Thomas Lumley
Assistant Professor, Biostatistics
University of Washington, Seattle
-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-
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