Skip to content
Prev 166024 / 398502 Next

Sweave data-figure coupling

On Mon, Jan 05, 2009 at 01:52:00PM -0600, Sebastian P. Luque wrote:
I was very confused, too when I first had this happen to me. The
reason is that chunks with fig=TRUE are executed three times by
default: once for the eps file, the pdf and the default device.
Accordingly, whenever you modify data in such a code chunk, the
results change with each round of execution.

The solution to the problem is either 

 - separating the manipulations from the plotting in two code chunks 
 - or keeping the modified values in a separate variable instead of 
   modifying the original.

In your example you are modifying 'lik' and 'post'. Just call the
modified versions likMod and postMod or something like this and
your problem will go away.

cu
	Philipp