Hello list, I have found a problem (bug?) with Sweave. I hope that someone could help me. Try this little example : \documentclass[a4paper]{article} \title{toto} \author{toto} \begin{document} \maketitle <<ni1, fig=T, eval=TRUE, echo=TRUE, debug=TRUE, results=verbatim, include =FALSE, width=7, height=7>>a<-rnorm(1)+1 a plot(1:10) @ patati <<ni2, fig=F, eval=TRUE, echo=TRUE, debug=TRUE, results=verbatim, include =FALSE, width=7, height=7>>a @ \end{document} The value of 'a' has change between the two Schunks. It seems that the problem only appear when there are plot (fig=T) in the first one. Without plot, there are no problems: a remains unchanged. Is it a bug or have I misundertsood something ? Thanks a lot ! R version 2.1.0 (Debian). -- St??phane DRAY (dray at biomserv.univ-lyon1.fr ) Laboratoire BBE-CNRS-UMR-5558, Univ. C. Bernard - Lyon I 43, Bd du 11 Novembre 1918, 69622 Villeurbanne Cedex, France Tel: 33 4 72 43 27 57 Fax: 33 4 72 43 13 88 http://www.steph280.freesurf.fr/
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