I am dreaming if someday I have enough time to write a Chinese text book about how to use R to replace SPSS in processing survey datasets. I am dreaming this book is done with LyX and the R codes in the book are well incorporated into the book. Then I thought about Sweave, a tool that I heard about when I was in graduate school.
After some hours of reviewing concepts about shell and online materials about Sweave, I am writing down the steps for setting up the LyX-Sweave environment in a Linux (Fedora 11) machine:
A good guidance of installation and example Lyx files provided by Paul Johnson are available here: http://wiki.lyx.org/LyX/LyxWithRThroughSweave. Below is a bit updated information about the steps.
1. Create a file named Rweave in /usr/local/bin, where two lines of codes are put into the file:
2. Put Noweb.sty and Sweave.sty in /usr/share/texmf/tex/latex/noweb (create the folder "noweb" if necessary). Noweb.sty can be downloaded here and Sweave.sty is available in your R library: /usr/share/R/texmf/Sweave.sty.
3. In the terminal, change to the root, type "texhash" to update the tex system. Then go to LyX, Tools -> Reconfigure. Next, restart LyX.
4. In LyX, Tools->Preferences-->File Handling, choose "Noweb" in "From format" and "LaTeX(pdflatex)" in "To format". Then, in converter box, type "Rweave $$i". Hit Add and Save.
5. Then you can try to open the example files and making the pdf files.
After some hours of reviewing concepts about shell and online materials about Sweave, I am writing down the steps for setting up the LyX-Sweave environment in a Linux (Fedora 11) machine:
A good guidance of installation and example Lyx files provided by Paul Johnson are available here: http://wiki.lyx.org/LyX/LyxWithRThroughSweave. Below is a bit updated information about the steps.
1. Create a file named Rweave in /usr/local/bin, where two lines of codes are put into the file:
#!/bin/sh
echo "library(\"utils\"); Sweave(\"$1\")" | R --no-save --no-restore
2. Put Noweb.sty and Sweave.sty in /usr/share/texmf/tex/latex/noweb (create the folder "noweb" if necessary). Noweb.sty can be downloaded here and Sweave.sty is available in your R library: /usr/share/R/texmf/Sweave.sty.
3. In the terminal, change to the root, type "texhash" to update the tex system. Then go to LyX, Tools -> Reconfigure. Next, restart LyX.
4. In LyX, Tools->Preferences-->File Handling, choose "Noweb" in "From format" and "LaTeX(pdflatex)" in "To format". Then, in converter box, type "Rweave $$i". Hit Add and Save.
5. Then you can try to open the example files and making the pdf files.
No comments:
Post a Comment