Re: [R] Dynamically switching lattice device characteristics in Sweave under Makefile control

From: Deepayan Sarkar <>
Date: Tue, 24 Jun 2008 17:43:55 -0700

On 6/24/08, Douglas Bates <> wrote:
> I am indebted to Deepayan Sarkar for lattice graphics, Fritz Leisch
> for Sweave and the authors of the beamer package for LaTeX. For me
> these are a "killer app" combination. I wouldn't want to go back to
> creating presentations in any other way.
> When I create a presentation I use a Makefile that allows me to the
> presentation version of the slides, a 4-up version for printing on
> letter paper and a 4-up A4 version. Sample files can be found at
> When creating the printable versions I want to invoke something like
> lattice.options(default.theme = standard.theme(color = FALSE))
> in the "preliminaries" chunk so the 4-up slides can be printed on a
> black-and-white printer without losing too much information. I
> haven't worked out a way of passing this information in to the
> individual sections yet. I would welcome suggestions. If you look in
> the Makefile you will see that there is a fooD.tex and a fooH.tex file
> controlling whether the display or the other one (I forget why I
> called it H) is active. That is how I control the beamer stuff. The
> problem for me is that the device characteristics need to be
> controlled in the individual .Rnw files

The only general solution would probably be at the level of R CMD Sweave; i.e., going back to the old days, have something like

%.tex: %.Rnw

        echo "library(tools); library(lattice); lattice.options(default.theme = standard.theme(color = FALSE)); Sweave('$<') " | ${R_PROG} --vanilla --silent

A less general solution (that I use myself) takes advantage of the fact that Sweave by default produces both eps and pdf versions. You can have separate lattice settings for two devices, and it so happens that the default for postscript is black and white while pdf is color. So, once you have all your Rnw files processed,

texi2dvi --pdf foo.tex

will produce a pdf with color figures, and

texi2dvi foo.tex
dvips foo.dvi

will produce a pdf with black and white figures. Since the last sequence is usually needed only for one special .tex file (the handout version), I have it hard-coded in the Makefile.

-Deepayan mailing list PLEASE do read the posting guide and provide commented, minimal, self-contained, reproducible code. Received on Wed 25 Jun 2008 - 00:48:31 GMT

Archive maintained by Robert King, hosted by the discipline of statistics at the University of Newcastle, Australia.
Archive generated by hypermail 2.2.0, at Wed 25 Jun 2008 - 12:30:46 GMT.

Mailing list information is available at Please read the posting guide before posting to the list.

list of date sections of archive