[R] Sweave recode(car) and Lyx, compiling but not executing on Mac

Graham Smith myotisone at gmail.com
Fri Jun 12 16:27:08 CEST 2009


I am just beginning to use Sweave with Lyx on a Mac (R2.8.1). I have
12 chunks of Sweave code that work fine, but this piece:

<<>>=
library(car)
cabbages$Year<-recode(cabbages$Year,"'X2001'='2001';'X2002'='2002';'X2003'='2003';'X2004'='2004';'X2005'='2005';'X2006'='2006';'X2007'='2007';'X2008'='2008';'X2009'='2009';'X2010'='2010';'X2011'='2011';'X2012'='2012'")
@

just prints out verbatim as a single line running off the page (No
recoding occurs). It worked in R before pasting into Lyx.

Initially I had the double quotes and single quotes the other way
round, but this produced this in the complied pdf:
> cabbages$Year <- recode(cabbages$Year, "\"X2001\"=\"2001\";\"X2002\"=\"2002\";\"X2003\"=\"2003\";\ etc

The first double quote in the printout shown above was a single quote
before compiling.

I have asked on the Lyx forum for help, but maybe someone here can
suggest what I might be doing wrong. Of course it could be a Mac/Lyx
issue rather than an SWeave/R issue, but any help would be
appreciated.

Thanks,

Graham




More information about the R-help mailing list