There was some discussion on twitter about the fact that the manual
page for as.formula() doesn't mention reformulate(), and indeed the last
example is
## Create a formula for a model with a large number of variables:
xnam <- paste0("x", 1:25)
(fmla <- as.formula(paste("y ~ ", paste(xnam, collapse= "+"))))
which could arguably be better done as
reformulate(xname, response = "y")
I've attached a documentation patch that adds the alternative version
and a \seealso{} link.
Happy to submit to r-bugzilla if requested.
cheers
Ben Bolker
Index: formula.Rd
===================================================================
--- formula.Rd (revision 81462)
+++ formula.Rd (working copy)
@@ -158,9 +158,10 @@
\seealso{
\code{\link{~}}, \code{\link{I}}, \code{\link{offset}}.
- For formula manipulation: \code{\link{terms}}, and \code{\link{all.vars}};
- for typical use: \code{\link{lm}}, \code{\link{glm}}, and
+ For formula manipulation: \code{\link{terms}}, and \code{\link{all.vars}}.
+ For typical use: \code{\link{lm}}, \code{\link{glm}}, and
\code{\link{coplot}}.
+ For formula construction: \code{\link{reformulate}}.
}
\examples{
class(fo <- y ~ x1*x2) # "formula"
@@ -176,5 +177,8 @@
## Create a formula for a model with a large number of variables:
xnam <- paste0("x", 1:25)
(fmla <- as.formula(paste("y ~ ", paste(xnam, collapse= "+"))))
+## Equivalent with reformulate():
+fmla2 <- reformulate(xnam, response = "y")
+identical(fmla, fmla2)
}
\keyword{models}
______________________________________________
R-devel@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/r-devel