Hello all, I've been able to use R very successfully to run simple statistics and generate the plots I require. I've been evaluating Sweave, and have hit upon a small problem that I don't seem to be able to workaround. Sweave runs very well for single file latex documents, but I have a complex thesis made up of several parts and chapters. These are arranged with a master latex file and subdirectories with "\include"-ed latex fragments representing those parts/chapters, and I don't seem to be able to get Sweave to work properly. I've tried a number of approaches, including converting the master document into a Snw file itself, or even generating chapters manually chapter by chapter using Sweave and then "\include"ing the result into the master tex file. Unfortunately for the latter attempt, the the latex generated doesn't prepend the required path to the filename, and so latex looks for the pdfs and tex files in the wrong place - it looks in the "root" directory (where the master tex file is located) rather than the chapter subdirectory where all the files have been generated. I hope I'm not missing something obviously documented, but I can't see it in the Sweave docs. Is there an option to prepend a pathname to the filename of Sweave generated TeX and PDF documents? Do people use Sweave for complex multi-file latex projects, and what is the best approach? I'm almost tempted to keep R and Latex separate, and continue to run a R script to generate all of the dynamic tables/charts which are then "\input"ed, but I was rather attracted to the whole Sweave approach. Many thanks, Mark -- Dr. Mark Wardle Clinical research fellow and Specialist Registrar in Neurology, C2-B2 link, Cardiff University, Heath Park, CARDIFF, CF14 4XN. UK email: wardle at cardiff.ac.uk mark at wardle.org OpenPGP key: 66896A39
On 10/14/06, Mark Wardle <mark at wardle.org> wrote:> Hello all, > > I've been able to use R very successfully to run simple statistics and > generate the plots I require. > > I've been evaluating Sweave, and have hit upon a small problem that I > don't seem to be able to workaround. Sweave runs very well for single > file latex documents, but I have a complex thesis made up of several > parts and chapters. These are arranged with a master latex file and > subdirectories with "\include"-ed latex fragments representing those > parts/chapters, and I don't seem to be able to get Sweave to work properly. > > I've tried a number of approaches, including converting the master > document into a Snw file itself, or even generating chapters manually > chapter by chapter using Sweave and then "\include"ing the result into > the master tex file. Unfortunately for the latter attempt, the the latex > generated doesn't prepend the required path to the filename, and so > latex looks for the pdfs and tex files in the wrong place - it looks in > the "root" directory (where the master tex file is located) rather than > the chapter subdirectory where all the files have been generated. > > I hope I'm not missing something obviously documented, but I can't see > it in the Sweave docs. Is there an option to prepend a pathname to the > filename of Sweave generated TeX and PDF documents? > > Do people use Sweave for complex multi-file latex projects, and what is > the best approach? I'm almost tempted to keep R and Latex separate, and > continue to run a R script to generate all of the dynamic tables/charts > which are then "\input"ed, but I was rather attracted to the whole > Sweave approach.You haven't told us what platform you are using, but makefiles are the solution I would recommend if that's feasible. For example, the Makefile in one of my presentations might look like ----------------- R_PROG = R-2.4 R_HOME = `${R_PROG} RHOME` TPUTS = ${TEXINPUTS}:${R_HOME}/share/texmf/:tex/ TEX_COMPS = tex/defs tex/main RNW_COMPS = faithful barley qqaspect all: statgraphics.pdf statgraphics.tex: $(TEX_COMPS:=.tex) $(RNW_COMPS:=.tex) tex/statgraphics.tex cp tex/statgraphics.tex . clean: rm -f *.Rnw *.tex *.log *.dvi *.ps *.pdf *.R figs/* *~ */*~ %.Rnw: rnw/%.Rnw ln -s $< . %.tex: %.Rnw echo "library(tools); Sweave('$<')" | ${R_PROG} --vanilla --silent %.R: %.Rnw echo "library(tools); Stangle('$<')" | ${R_PROG} --vanilla --silent %.dvi : %.tex TEXINPUTS=${TPUTS} texi2dvi -q -c $< %.ps : %.dvi TEXINPUTS=${TPUTS} dvips -o -q $< %.pdf : %.tex TEXINPUTS=${TPUTS} texi2dvi -c -q --pdf $< -------------- Things are slightly complicated because I tend to keep .tex and .Rnw files in separate directories (but make a copy/link before running Sweave or latex on them). After a make clean, the top-level directory looks like: deepayan at kanika:statgraphics$ ls -R .: data figs Makefile rnw tex ./data: ./figs: ./rnw: barley.Rnw faithful.Rnw qqaspect.Rnw ./tex: defs.tex main.tex statgraphics.tex and deepayan at kanika:statgraphics$ grep input tex/*.tex tex/main.tex:\input{faithful1} tex/main.tex:\input{barley1} tex/main.tex:\input{qqaspect} tex/statgraphics.tex:\input{tex/defs} tex/statgraphics.tex:\input{tex/main} HTH, -Deepayan
>>>>> On Sat, 14 Oct 2006 23:00:27 +0100, >>>>> Mark Wardle (MW) wrote:> Hello all, > I've been able to use R very successfully to run simple statistics and > generate the plots I require. > I've been evaluating Sweave, and have hit upon a small problem that I > don't seem to be able to workaround. Sweave runs very well for single > file latex documents, but I have a complex thesis made up of several > parts and chapters. These are arranged with a master latex file and > subdirectories with "\include"-ed latex fragments representing those > parts/chapters, and I don't seem to be able to get Sweave to work properly. > I've tried a number of approaches, including converting the master > document into a Snw file itself, or even generating chapters manually > chapter by chapter using Sweave and then "\include"ing the result into > the master tex file. Unfortunately for the latter attempt, the the latex > generated doesn't prepend the required path to the filename, and so > latex looks for the pdfs and tex files in the wrong place - it looks in > the "root" directory (where the master tex file is located) rather than > the chapter subdirectory where all the files have been generated. > I hope I'm not missing something obviously documented, but I can't see > it in the Sweave docs. Is there an option to prepend a pathname to the > filename of Sweave generated TeX and PDF documents? Yes, simply set prefix.string to a path, not only a filename. E.g., \SweaveOpts{prefix.string=figs/myfile} will place all figures in subdir "figs" (you have to create the directory first manually) and call the separate files "myfile-XXX" where XXX is number or name of the chunk. > Do people use Sweave for complex multi-file latex projects, and what is > the best approach? I'm almost tempted to keep R and Latex separate, and > continue to run a R script to generate all of the dynamic tables/charts > which are then "\input"ed, but I was rather attracted to the whole > Sweave approach. I personally mostly use Makefiles as suggested by Deepayan. In addition there is \SweaveInput{} which works similar to Latex's own \input{} command. There currently is no equivalent of \include{}. HTH, Fritz -- ----------------------------------------------------------------------- Prof. Dr. Friedrich Leisch Institut f?r Statistik Tel: (+49 89) 2180 3165 Ludwig-Maximilians-Universit?t Fax: (+49 89) 2180 5308 Ludwigstra?e 33 D-80539 M?nchen http://www.stat.uni-muenchen.de/~leisch