[Rd] Variable names with spaces in lm
ggrothendieck at gmail.com
Mon May 9 23:43:22 CEST 2005
There is one other problem with the coercion to data.frame.
terms.formula does not actually use the data contents, I think, so if it
did not coerce to a data frame it could handle unequal length
data in lists too.
On 09 May 2005 19:37:25 +0200, Peter Dalgaard <p.dalgaard at biostat.ku.dk> wrote:
> Gabor Grothendieck <ggrothendieck at gmail.com> writes:
> > 'lm' gives an error when using variables with spaces in them
> > in certain cases (but not all):
> > my.list <- list(`a 1` = 1:4, `a 2` = 11:14)
> > lm(`a 1` ~ ., my.list) # Error : Object "a.1" not found
> > # The following work ok so it does work in many cases:
> > lm(`a 1` ~ ., as.data.frame(my.list, optional = TRUE)) # ok
> > lm(`a 1` ~ `a 2`, my.list) # ok
> > Admittedly ?lm says that the data argument should be
> > a data frame or environment so this is not strictly a bug
> > but it seems to work with a list and the code even seems to
> > coerce it to a data frame.
> > I am using Windows XP "R version 2.1.0, 2005-04-18".
> As you probably gathered, the issue is that there's an as.data.frame()
> without optional=TRUE sitting inside terms.formula which causes the
> "." to expand to a.1 + a.2. Sounds like that's unconditionally a bug,
> but I'm a little unsure...
> O__ ---- Peter Dalgaard Blegdamsvej 3
> c/ /'_ --- Dept. of Biostatistics 2200 Cph. N
> (*) \(*) -- University of Copenhagen Denmark Ph: (+45) 35327918
> ~~~~~~~~~~ - (p.dalgaard at biostat.ku.dk) FAX: (+45) 35327907
More information about the R-devel