r - grid: Grid graphics flickering -


i'm designing interactive plot using grid package in r. part of interactivity, repeatedly delete , re-create various parts of plot. however, total number of grid elements (as obtained using grid.ls() command) stays constant; create removed.

the problem follows - once i've gone through few cycles of creation , deletion, every deletion make graphic, small, causes interactive parts of plot (those i've been repeatedly deleting , creating) flicker.

here's simplest example come - first run code set grid graphic, , repeatedly delete , re-create elements

library(grid)  pushviewport(viewport())  (x in seq(0, 1, length=5)) {     (y in seq(0, 1, length=5))     {         pushviewport(viewport(x = x, y = y, width=1/5, height=1/5, name=paste("foo", x, y, sep="")))         grid.rect()          pushviewport(viewport(x = 0, 0, width=1/4, height=1/4, name="bar1"))         grid.circle(name="testing")         grid.text("123")         upviewport()          pushviewport(viewport(x = 1, 0, width=1/4, height=1/4, name="bar2"))         grid.circle(name="testing")         grid.text("123")         upviewport()          pushviewport(viewport(x = 0, 1, width=1/4, height=1/4, name="bar3"))         grid.circle(name="testing")         grid.text("123")         upviewport()          pushviewport(viewport(x = 1, 1, width=1/4, height=1/4, name="bar4"))         grid.circle(name="testing")         grid.text("123")         upviewport()          upviewport()     } }  (i in 1:10) {      grid.gremove("testing")      (x in seq(0, 1, length=5))     {         (y in seq(0, 1, length=5))         {             downviewport(paste("foo", x, y, sep=""))              downviewport("bar1"); grid.circle(name="testing"); upviewport()             downviewport("bar2"); grid.circle(name="testing"); upviewport()             downviewport("bar3"); grid.circle(name="testing"); upviewport()             downviewport("bar4"); grid.circle(name="testing"); upviewport()              upviewport()         }     }  } 

once set up, create new arbitrary square on device

grid.rect(height=0.5, width=0.5, gp=gpar(lty = 2), name = "lastshape") 

now try delete it

grid.gremove("lastshape") 

notice when run last deletion command, small circles i've been creating , deleting flicker slightly, though haven't touched them. makes entire graphic distracting.

any ideas how prevent that?

thanks million!

@hadley - da boss! first comment provided correct answer; i'm copying , expanding here future reference...

all need use

dev.hold()  # .... scary modifications ...  dev.flush() 

seems work treat. i'll re-post if breaks again.

note: available in r v3 onwards...


Comments

Popular posts from this blog

javascript - DIV "hiding" when changing dropdown value -

Does Firefox offer AppleScript support to get URL of windows? -

android - How to install packaged app on Firefox for mobile? -