Skip to content
Prev 1315 / 3656 Next

"Graphics history" in UNIX

On Wed, Jun 9, 2010 at 5:42 PM, Scotti Roberto <roberto.scotti at gmail.com> wrote:
The basic tools required are still available. For example, you can
easily do manual (command-line) recording and replaying thus:

rp <- function()
{
    env <- environment()
    recorded <- list()
    current <- 0L
    record <- function()
    {
        current <<- length(recorded) + 1L
        recorded[[current]] <<- recordPlot()
        print(current)
    }
    replay <- function(n = current - 1L)
    {
        if (n > 0 && n <= length(recorded)) {
            current <<- n
            replayPlot(recorded[[current]])
        }
        else message("'n' not in valid range: ", n)
    }
    restore <- function() replay(n = length(recorded))
    showPrevious <- function() replay(n = current - 1L)
    showNext <- function() replay(n = current + 1L)
    env
}

rp <- rp()


plot(1:10) ## plot something
rp$record() ## record it
plot(rnorm(10)) ## plot something else
rp$record() ## record it

rp$showPrevious() ## show previous plot
rp$restore() ## show last recorded plot


The main trick is to (1) have the plots saved automatically whenever a
new page is created and (2) have a GUI interface for navigating
through the history. (1) needs device support (only the device really
knows when a new page is created), although you can get a partial
solution using user-level hooks. (2) needs some sort of GUI interface
to be available, which isn't really there for the x11 device.

So in short, it's technically feasible, but not supported by the
standard screen device. There are third party screen devices
available, and it would be easier for them to support recording (if
they don't already).

-Deepayan