[R] lattice / pdf bug ?

Dirk Eddelbuettel edd at debian.org
Tue Jul 27 01:17:49 CEST 2004


I've been scrathing my head over this one.  Suppose I have a data.frame
which maps to a 'n x k' lattice, and that one of those cells is empty.

An artificial example is generated by

Q<-data.frame(x1=sample(c("A","B"),10,replace=TRUE),
              x2=c("C", rep("D",9)), y=rnorm(10))

where by having only one obs. for the first level of the second factor x2,
we ensure that there won't be full combinations of x1 and x2.

This seems to trip panel.mathdensity(), but only when printing to pdf, and I
can't find a way to avoid it. Consider

		  
stopifnot(require(lattice))
stopifnot(require(grid))

pdf("testfile.pdf")
Q<-data.frame(x1=sample(c("A","B"),10,replace=TRUE),
              x2=c("C", rep("D",9)), y=rnorm(10))
print(histogram(~ y | x1+x2, data=Q,
                panel = function(x, ...) {
                  if (length(x) > 0) {
		    panel.histogram(x, ...)
                    panel.mathdensity(dmath = dnorm, col = "black",
                                      args = list(mean=mean(x, na.rm=TRUE), 
                       		                  sd=sd(x, na.rm=TRUE)))
                  }
                }))
dev.off()


where the resulting pdf file is broken if and only if the panel.mathdensity
call is present.  Without it, it works.  To the screen, it works with and
without -- but copying to pdf again  breaks the pdf file if
panel.mathdensity is used.

It is possible that I am overlooking something simple -- or is it a genuine
bug?

Platform is win2k, R version is 1.9.1.

Thanks for any pointers,  Dirk

-- 
Those are my principles, and if you don't like them... well, I have others.
                                                -- Groucho Marx




More information about the R-help mailing list