[R] Sweave / Latex per-chapter output

Anne-Marie Ternes amternes at gmail.com
Wed May 21 11:40:50 CEST 2008


Dear R-help,

I am using Sweave and pdflatex to generate a large report from data
contained in my database (Postgres via RODBC). Currently, I work with
a single R/Sweave file, containing several "chapter" indications for
the Latex engine. My master tex file sets the document class, and
includes the introduction, the main Sweave file, and a conclusions and
reference file. I use a makefile to produce the final PDF (based on
the thread "Sweave, R and complex latex projects:
http://tolstoy.newcastle.edu.au/R/e2/help/06/11/4891.html)

What I would like to do, is to be able to get 2 types of output with
the same code (I'm lazy ;-) ):
1. my large report in a single PDF file, for printing out and distributing
2. a PDF and HTML file *per chapter*, for displaying on our website
and allowing people to download individual chapters

I have tried the following things:
- see if pdflatex has an option to split PDF output per chapter; as
far as I see, it doesn't
- separate the Sweave file into chapter parts. The problems here are
1) that I do a certain number of R preparations (variables setting,
table querying) which are data that I will need in later parts of the
code, 2) that I would need to embed the generated tex files with
per-chapter master tex files setting the documentclass and other
options and including the chapter; I also tried to see if it was
possible to tell pdflatex to assume documentclass X even if it wasn't
specified in the file, but that doesn't seem to work either
- generate my large PDF report as usual and manually cut it into
chapters (tedious)
- use R via PHP to output per-chapter HTMLs which I could turn into
PDFs using output buffering; this works for the graphics, but I'm
unable to get back e.g. tabular data for proper display; also I would
loose the latex-y beauty of my PDF

As I'm a novice in Latex and Makefiles usage, I'd be glad if you could
tell me if what I want to do is feasible (I'm sure it is), and which
would be the best, fussless method to do it (i.e. generate both types
of output without changing the R/Sweave code).

I know you'll probably tell me to break my long Sweave code into
smaller parts, but as I briefly said above, I do some variable setting
and table querying at the start - things I will repeatedly need in
later chapters (e.g. I query a population table for computing
incidence rates several times in later chapters). If there is a better
way to split the code without having to requery the database at each
chapter, I'll be glad to know about that too!

BTW, I'm working on Ubuntu Linux.

Thanks a lot for your insight,

Anne-Marie



More information about the R-help mailing list