Persistence of graphics in Plots pane

I'm working in RStudio
Version 1.1.442 – © 2009-2018 RStudio, Inc.
Mozilla/5.0 (Macintosh; Intel Mac OS X 10_11_6) AppleWebKit/601.7.8 (KHTML, like Gecko)

I run code to produce some plots. When I come back a few days later to the still-open RStudio session, and try to cycle through my graphics, I get error messages as below for every graphics instance I manoeuvre to.

Is there a way to set a graphics storage location other than /var/folders so that the graphics materials remain persistent over many days? Or reset some setting so that R caching is not temporary (I see /Rtmp8E6kC9/ in the directory path).

Error in readChar(con, 5L, useBytes = TRUE) : cannot open the connection
In addition: Warning message:
In readChar(con, 5L, useBytes = TRUE) :
  cannot open compressed file '/var/folders/0n/7kqmtc1x45jfj5m20lnsmrkm0000gn/T/Rtmp8E6kC9/rs-graphics-9fd0456d-8f36-4d7d-9542-bfa3a92b214e/80de2c8f-dc2a-4dfe-a036-52b6d3fa4a76.snapshot', probable reason 'No such file or directory'
Graphics error: Plot rendering error
Error in readChar(con, 5L, useBytes = TRUE) : cannot open the connection
In addition: Warning message:
In readChar(con, 5L, useBytes = TRUE) :
  cannot open compressed file '/var/folders/0n/7kqmtc1x45jfj5m20lnsmrkm0000gn/T/Rtmp8E6kC9/rs-graphics-9fd0456d-8f36-4d7d-9542-bfa3a92b214e/3b04968a-5f55-4047-beb7-27536f0d3ebb.snapshot', probable reason 'No such file or directory'
Graphics error: Plot rendering error
Error in readChar(con, 5L, useBytes = TRUE) : cannot open the connection
In addition: Warning message:
In readChar(con, 5L, useBytes = TRUE) :
  cannot open compressed file '/var/folders/0n/7kqmtc1x45jfj5m20lnsmrkm0000gn/T/Rtmp8E6kC9/rs-graphics-9fd0456d-8f36-4d7d-9542-bfa3a92b214e/124a2d5e-8cac-4d30-9c90-0e79e9e8d4d8.snapshot', probable reason 'No such file or directory'
Graphics error: Plot rendering error

RStudio uses the R temporary directory for its plots, and that temporary directory can be configured as documented in ?tempdir:

By default, ‘tmpdir’ will be the directory given by ‘tempdir()’.
This will be a subdirectory of the per-session temporary directory
found by the following rule when the R session is started. The
environment variables ‘TMPDIR’, ‘TMP’ and ‘TEMP’ are checked in
turn and the first found which points to a writable directory is
used: if none succeeds ‘/tmp’ is used. The path should not
contain spaces. Note that setting any of these environment
variables in the R session has no effect on ‘tempdir()’: the
per-session temporary directory is created before the interpreter
is started.

You might want to try setting an alternate TMPDIR e.g. in your ~/.Renviron file.

Thank you Kevin.

I put

TMPDIR=/Users/stevenmckinney/RStudioTemp

in my .Renvron file. A fresh RStudio session put graphics files there, and they have been persistent over days.

1 Like