On Thu, Mar 20, 2008 at 9:39 AM, Andrew Barr <[EMAIL PROTECTED]> wrote: > Hi all, > > Using Lyx 1.5.2 and MiKTeX 2.5 on XP. I am trying to use the Sweave > to create literate-article documents. I haven't found great > documentation for how to do this on a windows install, but I have > pieced together the following steps, that ultimately fail when I try > to produce any layout by any method. I get the following error. > "Lyx:Cannot convert file. An error occured whilst running R CMD > Sweave "newfile2.Rnw"". Anybody know why? >
Hello, everybody. Here are the instructions for how we did succeed in using Sweave with LyX in Windows. I do not use Windows, but I have seen this work. I might test it out and see if I can fix it if somebody promises to send me a t-shirt. I think either you can follow this plan or study this plan and then try to update it to the approach that Gregor proposes. Gregor takes advantage of the fact that Sweave is now a command line batch option for R, but the way that Windows interacts with the environment is so different from Unix that I'm not optimistic that something so simple will work. Here is my warning. Your R code mistakes do not finish gracefully with Lyx & Sweave. The only way to tell what works is to run LyX from a terminal window, where you can see the R error messages. If you start LyX from an Icon, as Windows users are prone to do, then you will be completely helpless. My student Frank Liu worked this set of instructions. I understand that he has many students in Taiwan who are doing this, and I will contact him to see if he has newer information. I'm pretty sure that the library(tools) in the script below should be changed to library(utils). I also think the last two lines of that script are not strictly necessary. pj -------- Original Message -------- Subject: Re: Rweave for Windows Lyx (problem solved!) Date: Sat, 04 Mar 2006 17:06:22 -0600 From: Cheng-shan (Frank) Liu Thank you, Nicolás. Also thank Uwe Ligges, Brian D. Ripley, and Paul Johnson for their advices. Here is a summary of the advices about how to make Rweave work in Lyx under Windows: Suppose your Lyx is installed in C:\ProgramFiles\Lyx and your R in C:\ProgramFiles\R-2.2.1. 1. Create a R file "MakeSweave.R" with the following lines and then put it in "C:\ProgramFiles\Lyx\bin\" (this is a path registered in Lyx). library(tools) args <- commandArgs() inp <- args[length(args)] Sweave(inp) base <- sub("\.(Rnw|Rtex)$", "", inp) texi2dvi(paste("base", ".tex", sep=""), pdf=TRUE) shell.exec(paste("base", ".pdf", sep="")) 2. Create a batch script called "Rweave.bat" with the follwowing line, and put it in "C:\ProgramFiles\Lyx\bin\". (Note that back slash "/", rather than slash "/", is used in the script.) C:/ProgramFiles/R-2.2.1/bin/Rterm --no-save --args "%1" <C:/ProgramFiles/LyX/bin/MakeSweave.R> "%1.log" 3. Put noweb.sty (can be found in google, or simply grab this file: http://www.lsi.upc.es/~tpl/noweb.sty) in C:\ProgramFiles\Miktex\tex\latex\noweb\ and refresh MikTex. 4. Reconfigure Lyx (go to Edit-> Reconfigure). Check if you have document class "article(noweb)" (Layout->Document), If not, you may need to reinstall Lyx. 5. Last, make Lyx recognize the converter script Rweave. Go to Edit->Preferences->Converters. In the "From" pulldown, choose Noweb. In the "To" pulldown, choose LaTeX. Hit the "new" button toward the bottom. Then, make sure the Converter Noweb->LaTeX is chosen, and in the box called "Converter" type "Rweave $$i" without the quotation "". To test if the installation is done, check out Dr. Paul Johnson's example file (http://pj.freefaculty.org/stat/Distributions/Gamma-02.lyx ). See if you can view its pdf file. -Frank Liu -- Paul E. Johnson Professor, Political Science 1541 Lilac Lane, Room 504 University of Kansas