2009-07-16

LyX-Sweave: mandatory use of control+enter in code chunks

A user of LyX-Sweave is asking:
My embarrassingly simple question is this: For class notes, I often have lots of code to include. I develop code in R, & paste code into a scrap section. But then I have to step through it all and find the spots to insert control-enter to terminate lines. Inevitably I miss a few, then the code breaks (without a clue as to where). So, is there a simple way to move the code into a scrap that bypasses the control-enter problem?
First of all, you can easily see where Sweave has problem by launching LyX from the terminal. Then you will see the output of R CMD Sweave in the terminal and you can easily spot the problematic chunk. This works on MS Windows as well as on Linux! There is some development going on with LyX and it seems that it will be possible in the future to see the Sweave log in LyX directly as it is possible for LaTeX log.

I agree that mandatory the use of cotnrol+enter in scrap (code chunk) environment is suboptimal. I also hate it! But that is the way LyX is created. One way you can avoid this for now is to not use the "scrap" environment at all - you can insert the code chunks (starting with <<>>= and ending with @) in the LaTeX code (use shortcut control+l). I tried this on my laptop and works without problems. In future versions of LyX this resctriction might be lifted.

1 comment:

Gorjanc Gregor said...

Yihui Xie found a nice solution.