I followed along with the LyX noweb instructions and have succeeded in using LyX to create NoWeb documents that can be sent to the statistical program R and turned into LaTex by R's Sweave program.

I was using Emacs for things like this, but found I made about 9 times more errors writing equations in the old LaTeX way than I make with LyX. Because I figure I will have to do this on 10 different computers with 10 different users, I wrote down how I did it and pasted it below.

Here's my question. I would like to make LyX send code chunks to R interactively, so that I don't have to process the whole monstrously huge LyX document and all attendant R code. If I'm using Emacs, there's a package called ESS that allows me to open an R session and then pipe command chunks over.

How about telling me how I can do that with LyX?



HOWTO info---------------------------

For information on the statistical program R, consult http://www.r-project.org.

For more info on Sweave in R, you can consult the FAQ from the author of Sweave, the R component that does the processing of the Rnw file.

http://www.ci.tuwien.ac.at/~leisch/Sweave/FAQ.html

There are 3 steps to make LyX work with Sweave.

1. Put the "batch" script for processing Rnw files into an executable file and save it in your path. That file is in the Sweave documentation, but here it is again for reference. I named it Rweave. The version recommended by the Sweave author is this:

Rweave:
#!/bin/sh
echo "library(tools); Sweave(\"$1\")" | R --no-save --no-restore


I've seen various renditions of this script.


2. Fool LyX into thinking you have the whole of Noweb installed. Noweb is a package you can download and install, but you don't need it all. All you need is the noweb.sty file, the LaTeX style file. Install that in your LaTeX, I put it under


/usr/local/share/texmf/tex/latex/noweb

because that's a standard place to store user added latex files. If you want, I could package up my /usr/local/share/texmf directory and you could untar into your system. I also have the LaTeX files for the "beamer" presentations I make in LyX, those are the ones I show in Pols 110 when I don't use Powerpoint.

After dropping the noweb.sty file in, then run

> texhash

to make sure your LaTeX system knows about the file.

3. Configure LyX.

First, open LyX, choose "edit" and "reconfigure" and let it run. You should notice in the output it finds the noweb style and now you get new document classes.

Close LyX, restart.

Now you need to configure LyX. LyX needs to know that your file is a NoWeb file and that it has to be "post processed". Ordinarly, LyX goes directly from *.lyx format to *.tex format, but now it will go from *.lyx to *.nw format. You have to tell it how to handle the nw file.

In Lyx, you will see the document classes now include "Noweb" variants. Choose article(Noweb). THat tells Lyx that you want to process your file through another program. Now you have to tell LyX what that other program is. In Lyx's Edit / Preferences dialog, choose the "Converters" option. This menu interface is confusing. Here's the way it should go.

a. In the "From" pulldown, choose NoWeb
b. In the "To" pulldown, choose LaTeX
c. Hit the "new" button toward the bottom.
d. Make sure the Converter NoWeb->LaTeX is chosen, and then in the box called "Converter" type the name of the batch script you saved above. Mine was called Rweave, so I put Rweave in there. THe syntax should be


Rweave $$i

--
Paul E. Johnson                       email: [EMAIL PROTECTED]
Dept. of Political Science            http://lark.cc.ku.edu/~pauljohn
1541 Lilac Lane, Rm 504
University of Kansas                  Office: (785) 864-9086
Lawrence, Kansas 66044-3177           FAX: (785) 864-5700

Reply via email to