[Rd] formula(model.frame(y~.^2, data=d)) does not return formula from terms attribute of the model.frame

William Dunlap wdunlap at tibco.com
Fri Jan 7 02:29:42 CET 2011


In R 2.12.0 I get
  > d <- data.frame(x=1:10, y=log(1:10), f3=LETTERS[rep(1:3,c(3,3,4))])
  > m <- model.frame(y~.^2, data=d)
  > formula(m)
  y ~ x + f3
In S+ formula(m) gives formula given to model.frame(),
but in R you have to do the following get that formula:
  > formula(attr(m, "terms"))
  y ~ (x + f3)^2

Would it break anything to add to the top of formula.data.frame
something like
  if (!is.null(tms <- attr(x, "terms"))) {
    return(formula(tms))
  }
so that formula() would retrieve the formula buried
in model.frame's output?

Bill Dunlap
Spotfire, TIBCO Software
wdunlap tibco.com 



More information about the R-devel mailing list