[R] Sweaving single master file to get multiple individualised reports
Charilaos Skiadas
cskiadas at gmail.com
Fri Nov 9 00:10:20 CET 2007
On Nov 8, 2007, at 5:42 PM, Edith Hodgen wrote:
> Hi
>
>
[snip]
> What I think the problem is (I'm hoping it's not)
> —------------------------------
> I've used odfWeave to do something similar, and was then able to
> specify both the infile and the outfile (and so could go something
> like
> infile = template.odf and outfile =
> paste("ReportName",schoolname,".odt",sep = "").
> This involved an R file that had
>
> # getting packages, reading data etc stuff
> :
> :
> # doing some pre-processing on project-wide totals- easier here where
> it can be debugged bit by bit
> :
> :
> for (i in 1:Nschools){
> # set indicator variable for school i or otherwise set up subset for a
> school
> :
> # more pre-processing for school/regional summaries
> :
> :
> infile <- "templateName.odt" # same for all schools/regions
> outfile <- paste("ReportName",schoolname,".odt",sep = "") # unique to
> school/region
> odfWeave(infile,outfile)
> }
>
> However, as far as I can see (admittedly, seldom very far) the
> equivalent Sweave call is just Sweave(SnwFile) which would create
> SnwFile.tex.
Sweave accepts outfiles as well, but you have to look at ?RweaveLatex
to find that out. Sweave just passes its extra parameters to that. I
use code like the following in an "analysis.r" file:
for (trs in unique(pulse$transmitter)) {
data <- subset(pulse, transmitter==trs)
fname <- paste("analysis",gsub("\\.","-",trs),".tex", sep="")
range.IPI <- cover(range(data$IPI))
Sweave("analysis.rnw", output=fname)
}
You can probably use "system" in that loop to also run pdflatex on
the resulting files. I had a hard time redirecting the output of
those calls where I wanted it, but it did work I think. What I ended
up doing instead was to create the following basic shell script instead:
echo "Creating TeX files ..."
R CMD BATCH --vanilla --quiet analysis.r
echo "Compiling TeX files ..."
for file in *.tex
do
pdflatex $file >>logs.log
done
(This is all on MacOSX, and I am guessing Linux would work as well.
Don't know what goes on in the Windows world I'm afraid.)
Hope this helps.
> What I'm hoping for
> —--------------------
> Any one or more of:
>
> - A blasting for lack of understanding that tells me it's all easy,
> really (plus a "how to" or a "where to find and actually see")
> - A work-around
> - An idiot's guide to how to do it using a shell script or equivalent
> (which I suspect to be the way to go)
> - Help with automatically LaTeXing (actually pdfLaTeXing) all the
> *.tex files generated as a batch.
>
> One advantage of the within-a-loop way of working is that when the
> report for one or more schools needs re-running this can be done
> without
> re-running the whole lot. This flexibility needs to be part of the
> final
> solution.
>
> Many thanks for any expertise and experience offered
>
>
> Edith Hodgen
> Statistician and Data Manager
> New Zealand Council for Educational Research
> Postal address: P.O. Box 3237, Wellington 6140
> Street address: Level 10, Education House, 178-182 Willis Street,
> Te Aro, Wellington 6011
> Phone: +64-4-802 1433
> Fax: +64-4-384 7933
> edith.hodgen at nzcer.org.nz
>
> Web site http://www.nzcer.org.nz
>
Haris Skiadas
Department of Mathematics and Computer Science
Hanover College
More information about the R-help
mailing list