r - Automatically save plot and associated code -


i save automatically each generated plot , associated code r session in specific directory.

i noticed rstudio stores every plots in temporary file (/tmp/rtmp*/*.png in linux). therefore .last function copies these files in save directory when close r. yet, copy associated code (i.e., ~ 10 last lines) these plots in *.rhistory files (using savehistory function). directory contain :

  • plot1.png
  • .plot1.rhistory
  • plot2.png
  • .plot2.rhistory
  • ...

first thing me understand how rstudio plot function works did not find sources. assume uses dev.copy() dev.list() outputs :

plot(0) dev.list() > rstudiogd       png          2         3  

have ideas?

edit : looking @ rstudio sources, found in tools.r file savegraphicssnapshot function still not understand how works ...

first of all, rstudio front-end r, "understand how rstudio plot function works" is... understand how r plot function works. can google around find documentation.

now, point: simplest way output result of plot() file use functions listed here (by way, recommend take site... it's great learning resource r). in code, put relevant function:

# simple example: x <- rnorm(1000) pdf('mytestplot.pdf') # redirect output of plot() function                       # pdf file hist(x) dev.off() # "turn off" output "redirecting"... after invoking           # function, plots shown again in plot viewer 

other functions:

  • png(): output png file
  • jpeg(): output jpeg file
  • and on

hope helps


Comments

Popular posts from this blog

android - MPAndroidChart - How to add Annotations or images to the chart -

javascript - Add class to another page attribute using URL id - Jquery -

firefox - Where is 'webgl.osmesalib' parameter? -