Winston Chang
2018-Apr-02 17:23 UTC
[Rd] recordPlot/replayPlot not working with saveRDS/readRDS
The documentation for recordPlot says the following:> As of R 3.3.0, it is possible (again) to replay a plot from another R session using, for example, saveRDS and readRDS.However, I haven't been able to save and restore a plot displaylist and have it work within the same R session, using R 3.4.3 or 3.3.3. Here's an example: # Save displaylist for a simple plot png('test.png') dev.control(displaylist ="enable") plot(1:5, 1:5) r <- recordPlot() dev.off() # Replay plot. This works. png('test1.png') replayPlot(r) dev.off() # Save the plot and load it, then try to replay it. This does not work. saveRDS(r, 'recordedplot.rds') r2 <- readRDS('recordedplot.rds') png('test2.png') replayPlot(r2) ## Error: NULL value passed as symbol address dev.off() Is there something that I'm doing wrong here?
Paul Murrell
2018-Apr-02 21:41 UTC
[Rd] [FORGED] recordPlot/replayPlot not working with saveRDS/readRDS
Hi What you are doing "wrong" is loading a recordedplot into the same session that it was created in. The saveRDS()/readRDS() works if you save in one R session and then read in a different R session. The assumption is that if you are still in the same session that created the recordedplot you still have the recordedplot (e.g., you can just do replayPlot(r) instead of replayPlot(r2). Is that a bad assumption ? Paul On 03/04/18 05:23, Winston Chang wrote:> The documentation for recordPlot says the following: > >> As of R 3.3.0, it is possible (again) to replay a plot from another R session using, for example, saveRDS and readRDS. > > However, I haven't been able to save and restore a plot displaylist > and have it work within the same R session, using R 3.4.3 or 3.3.3. > Here's an example: > > # Save displaylist for a simple plot > png('test.png') > dev.control(displaylist ="enable") > plot(1:5, 1:5) > r <- recordPlot() > dev.off() > > # Replay plot. This works. > png('test1.png') > replayPlot(r) > dev.off() > > # Save the plot and load it, then try to replay it. This does not work. > saveRDS(r, 'recordedplot.rds') > r2 <- readRDS('recordedplot.rds') > png('test2.png') > replayPlot(r2) ## Error: NULL value passed as symbol address > dev.off() > > > Is there something that I'm doing wrong here? > > ______________________________________________ > R-devel at r-project.org mailing list > https://stat.ethz.ch/mailman/listinfo/r-devel >-- 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 http://www.stat.auckland.ac.nz/~paul/
Martin Maechler
2018-Apr-03 14:07 UTC
[Rd] [FORGED] recordPlot/replayPlot not working with saveRDS/readRDS
>>>>> Paul Murrell <paul at stat.auckland.ac.nz> >>>>> on Tue, 3 Apr 2018 09:41:56 +1200 writes:> Hi What you are doing "wrong" is loading a recordedplot > into the same session that it was created in. The > saveRDS()/readRDS() works if you save in one R session and > then read in a different R session. The assumption is > that if you are still in the same session that created the > recordedplot you still have the recordedplot (e.g., you > can just do replayPlot(r) instead of replayPlot(r2). Is > that a bad assumption ? Not "bad", really, but somewhat *un*intuitive I believe to most users, including me. I would have done the same as Winston to check if saving and loading of a recorded plot work fine. Also, the error message we get is not very helpful: > saveRDS(r, 'recordedplot.rds') > r <- readRDS('recordedplot.rds') > png('test2.png') > replayPlot(r) Error: NULL value passed as symbol address {coming from deep down: checkValidSymbolId() in src/main/dotcode.c } I've pondered a bit and in the end found it easy enough to tryCatch() the error, and "do the right thing" instead. As that should typically only happen in exactly such a use case, the change should be "uniformly >=" the previous state. Ideally, maybe we (R core) would provide an R level API to a "TRUE/FALSE" valued version of checkValidSymbolId() or its caller, so that *from R code* one could check if the recordedplot 'x' passed to replayPlot() with its external pointers needs to be fixed up by x <- restoreRecordedPlot(x) or not. But that would be another topic I'd not get envolved deeply just now. Martin> Paul > > On 03/04/18 05:23, Winston Chang wrote: > > The documentation for recordPlot says the following: > > > >> As of R 3.3.0, it is possible (again) to replay a plot from another R session using, for example, saveRDS and readRDS. > > > > However, I haven't been able to save and restore a plot displaylist > > and have it work within the same R session, using R 3.4.3 or 3.3.3. > > Here's an example: > > > > # Save displaylist for a simple plot > > png('test.png') > > dev.control(displaylist ="enable") > > plot(1:5, 1:5) > > r <- recordPlot() > > dev.off() > > > > # Replay plot. This works. > > png('test1.png') > > replayPlot(r) > > dev.off() > > > > # Save the plot and load it, then try to replay it. This does not work. > > saveRDS(r, 'recordedplot.rds') > > r2 <- readRDS('recordedplot.rds') > > png('test2.png') > > replayPlot(r2) ## Error: NULL value passed as symbol address > > dev.off() > > > > > > Is there something that I'm doing wrong here? > > > > ______________________________________________ > > R-devel at r-project.org mailing list > > https://stat.ethz.ch/mailman/listinfo/r-devel > > -- > Dr Paul Murrell > Department of Statistics > The University of Auckland
Winston Chang
2018-Apr-03 18:17 UTC
[Rd] [FORGED] recordPlot/replayPlot not working with saveRDS/readRDS
On Mon, Apr 2, 2018 at 4:41 PM, Paul Murrell <paul at stat.auckland.ac.nz> wrote:> Hi > > What you are doing "wrong" is loading a recordedplot into the same session > that it was created in. The saveRDS()/readRDS() works if you save in one R > session and then read in a different R session. The assumption is that if > you are still in the same session that created the recordedplot you still > have the recordedplot (e.g., you can just do replayPlot(r) instead of > replayPlot(r2). Is that a bad assumption ? > > PaulFor my particular case, the goal is to cache many plots to disk so that they can be replayed later, but still in the same R session. The plots may be replayed in the current session, and they may be replayed in a future one. Using a disk cache seems like a straightforward way to make the cached plots work for both cases. Also, the number of plots is such that a memory-based cache could consume significant amounts of memory. -Winston