[Rd] print.trellis(..., draw.in=...)

Gabor Grothendieck ggrothendieck at gmail.com
Sun May 21 13:41:55 CEST 2006

A year ago I had posted this code


and the associated discussion was that there would be a print.trellis
argument that could be used to eliminate the need for with.vpPath
or with.viewport there.  I assume that that is what draw.in= in
print.trellis is for.  When I try it I get an error.  I did notice that
?print.trellis says draw.in= has not been well tested yet.  Is
this a bug?

After running the the code at the end I get this error

 Error in downViewport.vpPath(vpPathDirect(name), strict, recording =
recording) :
        Viewport 'viewport[GRID.VP.1]' was not found

The only difference between the code below and the code in the
link above (which works) is that in the for loop at the end the
'with' in the code in the link has been removed and draw.in=
used in the print call in its place.

I am using Windows XP and get similar messages in 2.2.1 and
2.3.0 patched.


pushLayout <- function(nr, nc, name="layout") {
  pushViewport(viewport(layout=grid.layout(nr, nc), name=name))
  for (i in 1:nr) {
    for (j in 1:nc) {
      pushViewport(viewport(layout.pos.row=i, layout.pos.col=j))

names.vpPath <- names.viewport <- function(x) x$name

with.vpPath <- with.viewport <- function(data, expr, ...) {
      # if data is a vpPath it cannot be ROOT since
      # NULL will never dispatch here
      depth <- if (data$name == "ROOT") 0 else downViewport(names(data))
      result <- eval.parent(substitute(expr))

getChildren.viewport <- function(x) x$children


# specify number of cells to fill and number of rows
n <- 5; nr <- 3

nc <- ceiling(n/nr)
downViewport(pushLayout(nr, nc))

vpt <- current.vpTree(all = FALSE)
for(k in 1:n)
      print( xyplot(v ~ v, list(v = 1:k)), newpage = FALSE,
		draw.in = getChildren.viewport(vpt)[[k]] )

More information about the R-devel mailing list