R-beta: formula() and model formulae
Thomas Lumley
thomas at biostat.washington.edu
Tue May 6 21:36:16 CEST 1997
On 6 May 1997, Peter Dalgaard BSA wrote:
> Mike Meyer <mikem at 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 at stat.math.ethz.ch
=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
More information about the R-help
mailing list