Re: [R] Sweave bug? when writing figures / deleting variable in chunk

From: Peter Dunn <>
Date: Thu, 28 Jun 2007 11:31:44 +1000

> I have found a quite strange (to me) behaviour in Sweave. It only
> occurs in the following situation:

You need to understand what Sweave does when it creates pictures:
> <<>>=
> sel <- 1:5
> @
> <<fig=T>>=
> plot(trees[sel,])
> rm(sel)
> @

By default, a eps and pdf version of the graphic is made. That is, this chunk producing the graphic is *run twice*: once to make the eps file, once to make the pdf file.

After this code chunk is run once:

> <<fig=T>>=
> plot(trees[sel,])
> rm(sel)

...the variable sel is obviously deleted, so the second time it runs... well, there's your error message.

Best to place the command rm( sel ) in it's own separate chunk.


Dr Peter Dunn  |  dunn <at>
Faculty of Sciences, USQ;
Aust. Centre for Sustainable Catchments:

This email (including any attached files) is confidential an...{{dropped}}

______________________________________________ mailing list
PLEASE do read the posting guide
and provide commented, minimal, self-contained, reproducible code.
Received on Thu 28 Jun 2007 - 01:49:13 GMT

Archive maintained by Robert King, hosted by the discipline of statistics at the University of Newcastle, Australia.
Archive generated by hypermail 2.2.0, at Thu 28 Jun 2007 - 02:32:45 GMT.

Mailing list information is available at Please read the posting guide before posting to the list.