Martin Maechler
2003-May-12 13:38 UTC
same posting 6 times .. [Re: [R] grid - deleting grobs?]
Before everyone else starts shouting: This message seems to have been sent 6 times within a few minutes from the poster's mail server. I've stopped mail to our mailing lists from that server completely for the moment. Martin Maechler <maechler at stat.math.ethz.ch> http://stat.ethz.ch/~maechler/ Seminar fuer Statistik, ETH-Zentrum LEO C16 Leonhardstr. 27 ETH (Federal Inst. Technology) 8092 Zurich SWITZERLAND phone: x-41-1-632-3408 fax: ...-1228 <><
Hello! 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
Hi M.Kondrin wrote:> Hello! > 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 advanceYou can't delete grobs interactively. It is theoretically possible, but it has not been implemented (yet). [more detail on a reply shifted to R-devel] Paul -- Dr Paul Murrell Department of Statistics The University of Auckland Private Bag 92019 Auckland New Zealand 64 9 3737599 x85392 paul at stat.auckland.ac.nz
Hi M.Kondrin wrote:> Hello! > 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 advanceA grob is an R object containing an external pointer. For example, see ... gr <- grid.rect() unclass(gr) ... 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 graphical output. 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. Paul -- Dr Paul Murrell Department of Statistics The University of Auckland Private Bag 92019 Auckland New Zealand 64 9 3737599 x85392 paul@stat.auckland.ac.nz