2008-06-09

Using Sweave with LyX customisation script

Gabor suggested I should write a short batch file or R script which would copy the various files needed to use Sweave in LyX so that one does not need to actually do it onself. That would be nice, but there are several things that I should take care of:
  • I would need to find the LyX user/library directory. I do not know how to get his information in scriptable manner.
  • If the preference file already exists, I would have to append new content. That is easy, but in case some definitions are already used I would first need to parse the old version of prefences. That would not be so easy.
  • I would need to write a Unix shell script for Unix like systems and a batch file for MS Windows. I am not sure about Mac OS-X - I think Unix shell script should work there out of the box.
I think I will leave this step to someone else. I actually hope, that LyX developers might find a way to provide automatic customisation if R is installed on the computer. Some ideas were given here. Additionally, Gabors' {Sweave,Stangle}.bat could be used instead of {Sweave,Stangle}.sh that are shipped with R.

5 comments:

Steve said...

hi and thanks for your great work on Lyx/Sweave. I am using your tools on ubuntu but would like to know what I need to do to see R error messages. The Lyx error messages when there is an R error are not much help. Is there a way to view the R error messages directly other than just pasting the code back into an R session?

Gregor Gorjanc said...

Hi Steve!

As described in the R News paper, you can see the R errors, if you start LyX directly from the terminal/console. Say if I have a file test.lyx then I would use:


lyx test.lyx &


Steve said...

great, thanks, that works. sorry I missed the info in the paper.

Steve said...

... and one more thing, sorry to bother you, about looping -
suppose I want to print out a long-ish set of analyses for each of the n variables in a list (some charts, some tables etc, for each of the vars.). using odfweave what I do is weave the loop once to produce an .odt file with n chunks of the odfWeave code for each of the n variables, and then weave that intermediary file again to get the final .odt file. But I don't know how to do this with lyx and Sweave. Is there any way to produce iterated commands?

Gregor Gorjanc said...

Hi Steve!

If you can do the thing with the odfweave then there sure is a way to do it also with Sweave, but maybe the LyX side might be trickier.

I am guessing here, because you did not give an exact example! You have a file with a chunk of R code that creates a new file with n chunks of R code. But are you doing this "proliferation" step with odfweave or sweave? The problem with LyX might be the compilation feature of LyX - the weaving and compiling the LaTeX is done all in one way. However, you could use LyX to get the output with the temporary file. This can also be done from within the terminal. Please send me a reproducible so that we can be more exact!