[R] Sweave and Trellis in R 2.0.0patched (Windows)
Shawn Way
sway at tanox.com
Tue Oct 19 19:43:29 CEST 2004
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
More information about the R-help
mailing list