[R] Stangle - dropping re-used code chunks

Jason Turner jasont at indigoindustrial.co.nz
Sun Nov 23 17:56:02 CET 2003


My question is:  is there a way for Rtangle() to *not* print re-used 
code chunks?  It'd be easy enough to brew up a perl script to do just 
this, but if methods exist already, I'd rather use them.  My reading of 
the help pages and FAQs has missed something, if it's there.

Background:
I have course notes on R, written using Sweave.  I want to provide the R 
code separately so the course attendees don't have to re-type everthing 
in the manual.

In this manual, I typically show a command, then re-use the chunk to 
produce a plot.  Something like this:

%% first, show how the plot is done...
<<ex.ts.acf.mottle,echo=TRUE,fig=FALSE>>=
par(mfrow=c(2,2))
mottle.acf <- acf(mottle.t[,1], lag.max=45)
mottle.pacf <- pacf(mottle.t[,1], lag.max=45)
mottle.acf <- acf(mottle.t[,1], lag.max=45, ci.type="ma")
mottle.pacf <- pacf(mottle.t[,1], lag.max=45, ci.type="ma")

@

%% then plot it.

\begin{figure}[tbh]
   \centering
<<echo=FALSE,fig=TRUE>>=
<<ex.ts.acf.mottle>>
@
   \caption{Autocorrelation plot of the \Data{mottle} dataset.}
   \label{fig:ex.ts.acf.mottle}
\end{figure}
%% example ends

Stangle will (correctly) print the <<ex.ts.acf.mottle>> chunk twice, 
since it is called twice; once to create it, and once to re-use it.

Cheers

Jason
-- 
Indigo Industrial Controls Ltd.
http://www.indigoindustrial.co.nz
64-21-343-545
jasont at indigoindustrial.co.nz




More information about the R-help mailing list