Re: R-beta: formula() and model formulae

Thomas Lumley (thomas@biostat.washington.edu)
Tue, 6 May 1997 12:36:16 -0700 (PDT)


Date: Tue, 6 May 1997 12:36:16 -0700 (PDT)
From: Thomas Lumley <thomas@biostat.washington.edu>
To: r-testers <r-testers@stat.math.ethz.ch>
Subject: Re: R-beta: formula() and model formulae
In-Reply-To: <x2d8r4shh0.fsf@bush.kubism.ku.dk>

On 6 May 1997, Peter Dalgaard BSA wrote:
> Mike Meyer <mikem@stat.cmu.edu> writes:
> > 
> > Several bugs (no solutions, yet).  These might be well known.
> > 
> > 1) If one does, e.g.,  mymod <- lm(y ~ x); formula(mymod)
> > then one does not get back the formula (one gets, Error: invalid formula) 
> 
> Yep. Seems that we need a
> 
> formula.lm<-function(x)formula(x$terms)
> 

We also need to fix formula.default. At the moment it only looks for
x$formula.  Other standard places to keep a formula are x$call$formula and
x$terms.  How about 

formula.default<-function (x)
{
        if (!is.null(x$formula))
                return(eval(x$formula))
        if (!is.null(x$call$formula))
                return(eval(x$call$formula))
        if (!is.null(x$terms))
                return(x$terms)
        switch(typeof(x), NULL = structure(NULL, class = "formula"),
                character = formula(eval(parse(text = x)[[1]])),
                call = eval(x), stop("invalid formula"))
}

One disdvantage to extracting the formula from $terms instead of
$call$formula is that in S a terms object is not a formula. On the other
hand it doesn't really matter as long as people use the formula()
function.


Thomas Lumley
------------------------------------------------------+------
Biostatistics		: "Never attribute to malice what  :
Uni of Washington	:  can be adequately explained by  :
Box 357232		:  incompetence" - Hanlon's Razor  :
Seattle WA 98195-7232	:				   :
------------------------------------------------------------

=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
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@stat.math.ethz.ch
=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=