Save all plots already present in the panel of Rstudio

后端 未结 5 1366
一生所求
一生所求 2021-02-02 12:10

I\'ve made different plots (more than a hundred) for a project and I haven\'t capture them on the way (yes it\'s bad , i know). Now, I need to save them all at once but without

5条回答
  •  自闭症患者
    2021-02-02 12:45

    I am not sure how Rstudio opens the device where the plot are drawn, but I guess it uses dev.new(). In that case one quick way to save all opened graphs is to loop through all the devices and write them using dev.print.

    Something like :

    lapply(dev.list(),function(d){dev.set(d);dev.print(pdf,file=file.path(folder,paste0("graph_",d,".pdf"))})
    

    where folder is the path of the folder where you want to store your graph (could be for example folder="~" if you are in linux and want to store all your graph in your home folder).

提交回复
热议问题