Graham Smith
2009-Jun-12 14:27 UTC
[R] Sweave recode(car) and Lyx, compiling but not executing on Mac
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\";\ etcThe 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
John Fox
2009-Jun-12 16:12 UTC
[R] Sweave recode(car) and Lyx, compiling but not executing on Mac
Dear Graham, I just tried a similar recode() command using Sweave on a Windows system (not through LyX) and it worked fine. I hope this helps, John> -----Original Message----- > From: r-help-bounces at r-project.org [mailto:r-help-bounces at r-project.org]On> Behalf Of Graham Smith > Sent: June-12-09 10:27 AM > To: r-help at r-project.org > Subject: [R] Sweave recode(car) and Lyx, compiling but not executing onMac> > 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'=' 2>004';'X2005'='2005';'X2006'='2006';'X2007'='2007';'X2008'='2008';'X2009'='20 0> 9';'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 > > ______________________________________________ > R-help at r-project.org mailing list > https://stat.ethz.ch/mailman/listinfo/r-help > PLEASE do read the posting guidehttp://www.R-project.org/posting-guide.html> and provide commented, minimal, self-contained, reproducible code.
Graham Smith
2009-Jun-12 19:15 UTC
[R] Sweave recode(car) and Lyx, compiling but not executing on Mac
While this is a bit embarrassing , it seems I had two problems, one was that the recode command seems to need utf8 coding rather than the Lyx default (which is fine), plus I had typing error in the data set, which is not fine :-(. I rewrote my code using the with command which allowed it to run, but it then became obvious that the recoded resuts were not what I had expected. The typing error then being obvious. The first entry in my rcode was 'X2001'='2001' but the first level in the data set was "X20001" and this was enough to cause recode to fail in my original code, but run using the with command. Its now working. Thanks to everyone for there help. Graham 2009/6/12 Graham Smith <myotisone at gmail.com>:> 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 >