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

Graham Smith myotisone at gmail.com
Fri Jun 12 21:15:57 CEST 2009


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
>




More information about the R-help mailing list