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

Douglas Bates bates at stat.wisc.edu
Wed Jun 25 13:33:02 CEST 2008

On Tue, Jun 24, 2008 at 7:43 PM, Deepayan Sarkar
<deepayan.sarkar at gmail.com> wrote:
> On 6/24/08, Douglas Bates <bates at stat.wisc.edu> 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
>>  http://www.stat.wisc.edu/~bates/IMPS2008
>>  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
> ps2pdf foo.ps
> 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.

Thanks, Deepayan.

I was rather hoping that I could do something with environment
variables and the Makefile, along the lines of removing the .tex files
created from the .Rnw files and recreating them when I switched the
final output from D.pdf to H.pdf.  This would probably also require
touching a file name in the directory to keep track of whether the
figures were black and white or color.

More information about the R-help mailing list