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

From: Peter Dunn <dunn_at_usq.edu.au>
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.

P.

-- 
Dr Peter Dunn  |  dunn <at> usq.edu.au
Faculty of Sciences, USQ; http://www.sci.usq.edu.au/staff/dunn
Aust. Centre for Sustainable Catchments: www.usq.edu.au/acsc

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

______________________________________________
R-help_at_stat.math.ethz.ch mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
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 https://stat.ethz.ch/mailman/listinfo/r-help. Please read the posting guide before posting to the list.