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

From: <>
Date: Sun 19 Feb 2006 - 03:48:49 GMT

G'day Duncan,

>>>>> "DM" == murdoch <> 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.


        Berwin mailing list Received on Sun Feb 19 22:39:08 2006

This archive was generated by hypermail 2.1.8 : Mon 20 Feb 2006 - 03:21:41 GMT