From p.dalgaard at biostat.ku.dk  Mon May  9 19:37:25 2005
From: p.dalgaard at biostat.ku.dk (Peter Dalgaard)
Date: Mon May  9 19:37:34 2005
Subject: [Rd] Variable names with spaces in lm
In-Reply-To: <971536df050509061840ba9f7e@mail.gmail.com>
References: <971536df050509061840ba9f7e@mail.gmail.com>
Message-ID: <x2ekcgwbai.fsf@turmalin.kubism.ku.dk>

Gabor Grothendieck <ggrothendieck@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@biostat.ku.dk)             FAX: (+45) 35327907


[Rd] Variable names with spaces in lm
Peter Dalgaard