[Rd] Re: [R] grid - deleting and erasing grobs?
p.murrell at auckland.ac.nz
Wed May 14 10:31:13 MEST 2003
> Don't quite understand how can I delete grobs and simultaneously erase
> graphic output they produce. I first change grob's "vp" field to null
> (grid.edit(gr,vp=NULL)) to erase it and then call rm(gr) (as grobs are
> external pointers I'm not shure what this method actually frees
> allocated memory).
> May be there is simpler method?
> Does garbage collector have any effect on grobs?
> Thank you in advance
A grob is an R object containing an external pointer. For example, see ...
gr <- grid.rect()
... so simply doing rm(gr) does not necessarily do anything to the
external pointer (it just removes the R object). In particular, if
another grob contains the same external pointer, doing rm(gr) should
definitely not affect the external pointer. In the example above,
another object does contain the external pointer because drawing the
grid.rect() put a copy on grid's display list.
On top of that, doing rm(gr) is never going to trigger a redraw of
current image, so there is never going to be any visible change in
With regard to setting a grob's vp field to NULL: this has nothing to
do with whether the grob is drawn or not. A grob is always drawn within
the context of the current viewport. If a grob has a vp field AND that
field is not NULL, then the viewport in that vp field gets pushed before
the grob is drawn (and popped again afterward). So the vp field only
affects the context within which the grob is drawn.
It should be possible to write something like a grid.delete() function
which finds the grob on the display list, removes it, and replays the
display list to redraw the current image, minus the grob that was
deleted. (Some extra complications would arise if the grob was drawn in
more than one output device, and double-buffering on output devices
would make the redraw a whole lot nicer.) I will put a basic
grid.delete() function on my todo list, which I hope to put a dent in
during the second half of this year.
Dr Paul Murrell
Department of Statistics
The University of Auckland
Private Bag 92019
64 9 3737599 x85392
paul at stat.auckland.ac.nz
More information about the R-devel