Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Changing the Sweave driver from the command line

Tags:

r

latex

sweave

My current Makefile for weaving looks something like:

SUFFIXES: .tex .pdf .Rnw
MAIN = lecture
INCLUDES = chapter1.tex chapter2.tex ...

all: $(INCLUDES) $(MAIN).pdf

$(MAIN).pdf: $(INCLUDES) $(MAIN).tex

.Rnw.tex:
        R CMD Sweave $*.Rnw

.tex.pdf:
        pdflatex $*.tex


<snip>

Suppose I want to change the Sweave driver to use the highlight package (say). What's the best way of doing this?

like image 763
csgillespie Avatar asked Mar 27 '11 10:03

csgillespie


1 Answers

You could do what we do for the Rcpp* packages. Here is RcppGSL:

RcppGSL.pdf: RcppGSL/RcppGSL.Rnw
    cp -f RcppGSL/RcppGSL.Rnw .
    $(RSCRIPT) --vanilla -e "require(highlight); \
                             driver <- HighlightWeaveLatex(boxes = TRUE); \
                             Sweave( 'RcppGSL.Rnw', driver = driver ); "
    $(RSCRIPT) -e "tools::texi2dvi( 'RcppGSL.tex', pdf = TRUE, clean = FALSE )"
    bibtex RcppGSL
    $(RSCRIPT) -e "tools::texi2dvi( 'RcppGSL.tex', pdf = TRUE, clean = TRUE )"
    cp RcppGSL/RcppGSL-fake.Rnw RcppGSL.Rnw

This keeps the actual source and a 'fake' variant in a subdirectory inst/doc/RcppGSL/ to trick R into recreating the pdf only when we want it too---otherwise it sees an Rnw and pdf of the same basename and is happy.

A little more convoluted than the basic Makefile you started with, but currently still the only way to switch to highlight that we know.

like image 106
Dirk Eddelbuettel Avatar answered Sep 22 '22 08:09

Dirk Eddelbuettel