Quick way to save multiple open graphics windows in R?

1.8k views Asked by At

I know that I can save an image in a graphics window via a few options:

  • Right click image > Save...
  • File > Save as > ....

I also know that I can save multiple images by opening/saving to an external file (e.g., save(), pdf(), jpg(), png(), tiff(), etc.)

However, is there a way to save multiple OPEN device window images in R?

This would perhaps be necessary in instances such as this question or in instances in which plotting very complicated graphics takes so long that you'd rather not have to regenerate them (after initially failing to save the files to an external file).

P.S. I'm using R version 3.3.1 (64-bit) on Windows 7 machine. NOT using RStudio.

1

There are 1 answers

0
G5W On BEST ANSWER

List all the current graphics devices with dev.list(). Then loop through the list and save each one.

Open your multiple graphics windows. Then run:

for(d in dev.list()) {
    dev.set(d)
    Name = paste("Image", d, ".jpg", sep="")
    dev.copy(jpeg, Name)
    dev.off()
}

Of course, you can use formats other than jpeg if you like.