[R] problem using cat within Sweave code chunks when fig=TRUE
Paul.Rustomji at csiro.au
Paul.Rustomji at csiro.au
Mon Aug 25 01:49:22 CEST 2008
Hello R list
I was intending to use a cat statement within Sweave code chunks that
generate greaphs to generate a readme.txt file listing all the figures
generated with a brief caption along the lines of:
desired format of "readme.txt"
_________________________________
figure1.eps caption for figure1
figure1.pdf caption for figure1
figure2.eps caption for figure2
figure2.pdf caption for figure2
_________________________________
As an example, this block of sweave code replicates what I would like to
do in principle:
<<label=codechunk1,fig=TRUE,include=FALSE>>=
plot(1:10)
cat("figure1.eps caption goes here \n",file="readme.txt",append=T)
cat("figure1.pdf caption goes here \n",file="readme.txt",append=T)
@
<<label=codechunk2,fig=TRUE,include=FALSE>>=
plot(11:20)
cat("figure2.eps caption goes here \n",file="readme.txt",append=T)
cat("figure2.pdf caption goes here \n",file="readme.txt",append=T)
@
which I originally though would produce the desired result, however, the
cat statement appears to get executed three times producing:
readme.txt---
figure1.eps caption goes here
figure1.pdf caption goes here
figure1.eps caption goes here
figure1.pdf caption goes here
figure1.eps caption goes here
figure1.pdf caption goes here
figure2.eps caption goes here
figure2.pdf caption goes here
figure2.eps caption goes here
figure2.pdf caption goes here
figure2.eps caption goes here
figure2.pdf caption goes here
I have figured out that any sweave code with fig=TRUE appears to be
executed multiple times (up to three), presumably to write to both eps
and pdf graphics devices (not sure what the first/last execution does
though...).
Does anyone have any ideas about how to only execute the cat statements
the first time around so that the output looks like what I specified at
the top of this message?
Paul
Paul Rustomji
Rivers and Estuaries
CSIRO Land and Water
GPO Box 1666
Canberra ACT 2601
More information about the R-help
mailing list