Rev 85997 | Blame | Compare with Previous | Last modification | View Log | Download | RSS feed
% File src/library/grid/man/grid.grab.Rd% Part of the R package, https://www.R-project.org% Copyright 1995-2007 R Core Team% Distributed under GPL 2 or later\name{grid.grab}\alias{grid.grab}\alias{grid.grabExpr}\title{ Grab the current grid output }\description{Creates a \I{gTree} object from the current grid display listor from a scene generated by user-specified code.}\usage{grid.grab(warn = 2, wrap = wrap.grobs, wrap.grobs = FALSE, ...)grid.grabExpr(expr, warn = 2, wrap = wrap.grobs, wrap.grobs = FALSE,width = 7, height = 7, device = offscreen, ...)}\arguments{\item{expr}{ An expression to be evaluated. Typically,some calls to grid drawing functions. }\item{warn}{ An integer specifying the amount of warningsto emit. 0 means no warnings, 1 means warn when it iscertain that the grab will not faithfully represent theoriginal scene. 2 means warn if there's any possibilitythat the grab will not faithfully represent theoriginal scene.}\item{wrap}{ A logical indicating how the output shouldbe captured. If \code{TRUE}, each non-grob element on thedisplay list is captured by wrapping it in a grob.}\item{wrap.grobs}{ A logical indicating whether, if we are wrappingelements (\code{wrap=TRUE}), we should wrap grobs (or justwrap viewports).}\item{width, height}{ Size of the device used for temporaryrendering. }\item{device}{ A function that opens a graphics device for temporaryrendering. By default this is an off-screen, in-memory devicebased on the \code{pdf} device, but this default device may not besatisfactory when using custom fonts.}\item{\dots}{ arguments passed to \I{gTree}, for example, aname and/or class for the \I{gTree} that is created.}}\details{There are four ways to capture grid output as a \I{gTree}.There are two functions for capturing output:use \code{grid.grab} to capture an existing drawingand \code{grid.grabExpr} to capture the output froman expression (without drawing anything).For each of these functions, the output can be captured intwo ways. One way tries to be clever and make a\I{gTree} with a \I{childrenvp} slot containing all viewports onthe display list (including thosethat are popped) and everygrob on the display list as a child of the new\I{gTree}; each child has a \I{vpPath} in the \I{vp} slot so that it isdrawn in the appropriate viewport.In other words, the \I{gTree} contains all elements on the displaylist, but in a slightly altered form.The other way, \code{wrap=TRUE},is to create a grob for every element on thedisplay list (and make all of those grobs children of the\I{gTree}). Only viewports arewrapped unless \code{wrap.grobs} is also \code{TRUE}.The first approach creates a more compact and elegant \I{gTree},which is more flexible to work with,but is not guaranteed to faithfully replicate all possiblegrid output. The second approach is more brute force, andharder to work with, but is more likely to replicate the originaloutput.An example of a case that will NOT be replicated by wrapping,with \code{wrap.grobs=TRUE}, isa scene where the placement of one grob is dependent on another grob(e.g., via \code{grobX} or \code{grobWidth}).}\value{A \I{gTree} object.}\seealso{ \code{\link{gTree}}}\examples{pushViewport(viewport(width=.5, height=.5))grid.rect()grid.points(stats::runif(10), stats::runif(10))popViewport()grab <- grid.grab()grid.newpage()grid.draw(grab)}\keyword{ dplot }