[Rd] Bug in Sweave? -- scoping problem? (PR#8615)

berwin@maths.uwa.edu.au berwin at maths.uwa.edu.au
Sun Feb 19 04:48:49 CET 2006


G'day Duncan,

>>>>> "DM" == murdoch  <murdoch at stats.uwo.ca> writes:

    DM> I have found a strange scoping problem in Sweave.  [...]

    DM> The strange thing is that while the value in partytotal is
    DM> output correctly as [...]

    DM> but the dotchart contains the wrong values: it shows sorted
    DM> values, but not sorted names, [...]
No bug, but a feature. :)
(But then, a well known software producer seems to use `feature' as a
euphemism for `bug', so perhaps I shouldn't call it a feature.)

There was recently a discussion on r-help (?) about Sweave producing
different output in the text and plot when random numbers were
generated, and it seems as if you have run into the same trap:

      Code in chunks that produce pictures is executed several times.
      First, to produce the output in the text.  And then once more
      for *each* format in which the figure has to be produced.  I.e.,
      if you want a PDF and a PostScript version of the figure, the
      code is executed a total of three times.

All instances of this feature reported so far involved commands that
produced random numbers and the poster was surprised that the output
in the text and the figures differed (and that the two figures were
different).

In your case the first execution of the code assigns the names to
partytotal, sorts partytotal and produces the data.  On the next
execution, when the picture is produced, partytotal is already sorted
but you reassign the names.  Then the partytotal is sorted again and
the plot is produced.  But that re-assigning of names lead to the
disconnect between values and names.

Hope this helps.

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-devel mailing list