Search

Monday, January 22, 2007

Some expensive lessons I recently learnt about R/Sweave

1. If you are going to generate lots of latex tables automatically from an Rnw file, LABEL THEM.

2. weaver does not work with xYplot. If you are using the Hmisc library, just don't use weaver. I will present a solution here sometime soon.

The solution: set caching to off (cache=off) in the chunk that loads the Hmisc library and runs the xYplot command(s). You can turn caching on before and after the chunk, but xYplots need to be computed without caching.

3. xtable is unable to identify the fact that an R output line containing, e.g., log(sigma^2), has to be in math-environment in the tex. In Sweave this has the disastrous consequence that the .tex file does not compile. My kludgy solution is to search and replace the .tex file after Sweaving it.

It's frustrating that such good tools can sometimes be such a pain in the ass. I guess one should be grateful they are there at all.

2 comments:

Gorjanc Gregor said...

Do send comment to the author of weaver. This might get fixed in the future - maybe also with your solution you are planning to post here ;)

Gregor

Anonymous said...

Regarding your comment about xtable being unable to recognize the need for maintaining math fields, I wonder if you've read page 3 of the documentation about the "sanitize" functions.

xtable uses these functions to eliminate special characters that might cause TeX to go haywire. You can declare your own sanitize.rownames.function and
sanitize.colnames.function so that math characters can be processed any way you want.

If you can give an example of specifically what is causing you trouble....