[R] Sweave and Trellis in R 2.0.0patched (Windows)

Deepayan Sarkar deepayan at stat.wisc.edu
Tue Oct 19 20:29:27 CEST 2004


On Tuesday 19 October 2004 12:43, Shawn Way wrote:
>  I've been using the following code to plot using Sweave in version
> 1.9.1
>
> library(RODBC)
> library(lattice)
> channel <-odbcConnectExcel("h:/water.xls")
> data <- sqlQuery(channel,"select * from `Sheet1$` where Test = 'TOC'
> and (Valve='5010-05' or Valve='8030-V26' or Valve='1180-08' or
> Valve='5040-08')")
> odbcClose(channel)
> srt <- order(as.POSIXct(data$'DateTime Sampled'))
> data <- data[srt,]
> data <- data[!is.na(data$Value),]
> start1 <- strptime(c("6/1/2003"),format="%m/%d/%Y")
> end1 <- strptime(c("5/1/2004"),format="%m/%d/%Y")
> data.plot <- data[
>                   data$'DateTime Sampled'>= start1
> #                  & is.na(data$Exclude)
>                   & data$'DateTime Sampled' <= end1
>                   ,]
> trellis.par.set(theme=col.whitebg())
> print(xyplot(data.plot$Value~data.plot$'DateTime
> Sampled'|data.plot$Valve,
>            data=data.plot,
>            panel= function(x,y) {
>                       panel.xyplot(x,y,type="b")
>                       panel.abline(h=500,col="red")
>                     },
>            layout=c(1,4),
>            type="b",
>            main="TOC Values for Various Systems",
>            xlab="Date",
>            ylab="TOC (ppb)"
>           ))
>
> But under version 2.0.0 it gives the following error:
> > Sweave("M:\\Engineering\\Shawn\\BMF\\MECO\\Clean Steam\\32-04.rnw")
>
> Writing to file 32-04.tex
> Processing code chunks ...
>  1 : term hide eps pdf
> Error in "[<-"(`*tmp*`, pos.heights[[nm]], value = numeric(0)) :
>  nothing to replace with
> Error in driver$runcode(drobj, chunk, chunkopts) :
>  Error in "[<-"(`*tmp*`, pos.heights[[nm]], value = numeric(0)) :
>
>  nothing to replace with

This looks like code introduced in 2.0.0, so there's a good chance this 
is a bug. 

> Data.plot has the following structure:
> > str(data.plot)
>
> `data.frame': 436 obs. of  13 variables:
>  $ DateTime Sampled:`POSIXct', format: chr  "2003-06-02 00:00:00"
> "2003-06-03 00:00:00" "2003-06-03 00:00:00" "2003-06-03 00:00:00" ...
>  $ DateTime Tested :`POSIXct', format: chr  "2003-06-02 00:00:00"
> "2003-06-03 00:00:00" "2003-06-03 00:00:00" "2003-06-03 00:00:00" ...
>  $ System          : Factor w/ 2 levels "CLS","HWFI": 2 1 2 2 2 2 1 2
> 2 2 ...
>  $ Valve           : Factor w/ 4 levels "1180-08","5010-05",..: 1 2 1
> 3 1 3 4 1 3 3 ...
>  $ Value           : num    5.75 231.00   1.10   8.25   8.70 ...
>  $ LimitValue      : logi  NA NA NA NA NA NA NA NA NA NA NA NA ...
>  $ IC              : logi  NA NA NA NA NA NA NA NA NA NA NA NA ...
>  $ Test            : Factor w/ 1 level "TOC": 1 1 1 1 1 1 1 1 1 1 ...
>  $ Sampled         : Factor w/ 4 levels "EV","HL","HL, EV",..: 1 4 1
> 1 1 1 1 1 1 1 ...
>  $ Tested          : Factor w/ 3 levels "Contract","KO",..: 3 3 3 3 3
> 3 3 3 3 3 ...
>  $ Verified        : Factor w/ 1 level "EV": NA NA NA NA NA NA NA NA
> NA NA ...
>  $ Comment         : Factor w/ 1 level "Test": NA NA NA NA NA NA NA
> NA NA NA ...
>  $ Exclude         : Factor w/ 1 level "X": NA NA NA NA NA NA NA NA
> NA NA ...
>
>
> When I remove the print(...) from the xyplot, the code chunks
> executes fine (no plot but that is expected). This also does not
> happen when the code is directly placed into R, only using Sweave().

Which is a bit surprising. One explanation could be that this is 
something device specific. Could you try doing this interactively but 
in PDF and postscript devices?

Also, could you assign the result of the xyplot call to a variable, save 
it in a file (using save), and send it to me offline?

Deepayan




More information about the R-help mailing list