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>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(). Any thoughts? Thanks for all your help and a wonderful (and useful) product. ________________________________ "Policies are many, Principles are few, Policies will change, Principles never do." -John C. Maxwell ________________________________ Shawn Way, PE Engineering Manager
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 withThis 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
On Tuesday 19 October 2004 13:49, you wrote: [...]> > I've included the following files: > Plt.dat - This is the xyplot using save() > Full.data - This is the entire environment using save.image()Thanks. Turns out this was a bug in trellis.par.set (a missing assignment), and can be reproduced (in a fresh R session) by> library(lattice) > x11() ## or any other device > trellis.par.set(theme = col.whitebg()) > xyplot(1 ~ 1)Error in "[<-"(`*tmp*`, pos.heights[[nm]], value = numeric(0)) : nothing to replace with The issue was that a call to trellis.device() needs to be made somewhere along the way so that the proper settings are initialized (which would then be overwritten by 'theme'). trellis.par.set was detecting if it needed to do this, but wasn't handling the situation correctly, leading to inconsistent settings. This should be fixed in the next release of lattice. For now, a workaround (which is functionally equivalent to what you are doing now) is to replace trellis.par.set(theme = col.whitebg()) by lattice.options(default.theme = "col.whitebg") Deepayan [...]> 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