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

From: <murdoch_at_stats.uwo.ca>
Date: Sat 18 Feb 2006 - 19:41:37 GMT

I have found a strange scoping problem in Sweave. The following Rnw file doesn't produce the same output in Sweave as it does if I produce an R file using Stangle and execute that:


election <- data.frame(A=1:3, B=9:7, C=rep(0,3)) partytotal <- rep(0, ncol(election))
for (i in 1:ncol(election)) {

      partytotal[i] <- sum(election[,i], na.rm=TRUE) }

<<fig=true,width=12,height=6,echo=true>>= names(partytotal) <- names(election)
partytotal <- sort(partytotal)

The data.frame "election" contains columns which are vote counts for 3 parties, with rows being 3 electoral districts. The column totals are 6 for A, 24 for B, and 0 for C. I calculate those totals in a vector partytotal, assign the names to its entries, and then sort it.

The strange thing is that while the value in partytotal is output correctly as


  > names(partytotal) <- names(election)
  > partytotal <- sort(partytotal)
  > partytotal


   C A B
   0 6 24

  > dotchart(partytotal)

but the dotchart contains the wrong values: it shows sorted values, but not sorted names, which is also what is left over in my workspace after the Sweave call:

  > partytotal
   A B C
   0 6 24

These tests were run in R 2.2.1, but I see the same thing in today's R-devel.

Duncan Murdoch

R-devel@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/r-devel Received on Sun Feb 19 06:44:04 2006

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