Douglas Bates
2008-Jun-24 22:00 UTC
[R] Dynamically switching lattice device characteristics in Sweave under Makefile control
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 Should you be inclined to read the content of the slides (and do bear in mind that they are a work in progress, to be presented on Sunday) I will tell you I am particularly proud of the slide entitled "Definition of linear mixed-effects models" (about slide 13 - depending on how you count). In one slide that describes a very general form of the model.
Deepayan Sarkar
2008-Jun-25 00:43 UTC
[R] Dynamically switching lattice device characteristics in Sweave under Makefile control
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 filesThe 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. -Deepayan