[R] A 'sweave' strange problem !!!

Berwin A Turlach berwin at maths.uwa.edu.au
Sat Nov 12 09:34:18 CET 2005


G'day Stéphane,

>>>>> "SD" == Stéphane Dray <dray at biomserv.univ-lyon1.fr> writes:

    SD> I have found a problem (bug?) with Sweave.  [...]  The value
    SD> of 'a' has change between the two Schunks. It seems that the
    SD> problem only appear when there are plot (fig=T) in the first
    SD> one.  Without plot, there are no problems: a remains
    SD> unchanged. Is it a bug or have I misundertsood something ?
You have misunderstood something :) But it is quite subtle and it took
me some time to realise what was going on.

Note, that if an Sweave chunk produces a figure, then by default a PDF
and an EPS version of the figure is produced.  But R can produce only
one figure at a time, thus the chunk will be executed at least twice
if you set 'fig=TRUE' (and do not change any of the other arguments).

I noticed that even if I add 'eps=FALSE' or 'pdf=FALSE', the value of
'a' changed, if 'fig=TRUE'.  Only with 'fig=TRUE' and 'eps=FALSE' and
'pdf=FALSE' (don't ask me why I tried it), did the value of 'a' not
change.  Hence, my guess is that chunks that have 'fig=TRUE' are
executed once to produce the output for the .tex file and then they
are executed again to produce EPS and/or PDF output.  Thus such a
chunk is executed once, twice or thrice; depending on the settings of
'eps'and 'pdf'.

Thus, it is not a good idea to have statements in such chunks that
produce (pseudo-)random results.  

    SD> Thanks a lot !
My pleasure. HTH.

    SD> R version 2.1.0 (Debian).
Well, I guess the standard on this mailing list is to point out that
this is quite an old version of R and that the current one is R
2.2.0 (but that one has the same behaviour). :)

Cheers,

        Berwin

========================== Full address ============================
Berwin A Turlach                      Tel.: +61 (8) 6488 3338 (secr)   
School of Mathematics and Statistics        +61 (8) 6488 3383 (self)      
The University of Western Australia   FAX : +61 (8) 6488 1028
35 Stirling Highway                   
Crawley WA 6009                e-mail: berwin at maths.uwa.edu.au
Australia                        http://www.maths.uwa.edu.au/~berwin




More information about the R-help mailing list