How do I prevent Rplots.pdf from being generated? How do I prevent Rplots.pdf from being generated? r r

How do I prevent Rplots.pdf from being generated?


I know this is a very old post and surely the OP has solved this. But I encountered this similar situation while working with plotly. Converting a ggplot output into a plotly output generated the similar error of not being able to open file 'Rplots.pdf'.

I solved it by simply including :

pdf(NULL)

I'm not sure of the reason for the error, have not been able to figure that out, but this small line helped removing the error and displaying my plots as I would expect in plotly and ggplot combinations.


I wonder if you have another command that opens a device before or after the code snippet you've given us. When you're all done run dev.cur() to see if there was a device left open. If not, it should return the null device.

Here are ways you can recreate getting a Rplots.pdf or a Rplot001.png; the layout and par commands open a device if one isn't open, and since no filename has been given, it uses the default filename.

options(device="pdf")layout(1:4)dev.off()options(device="png")par()dev.off()

Maybe seeing that happen here will give you a clue as to what's happening with your code.


Here is the source code for CairoPNG:

function (filename = "Rplot%03d.png", width = 480, height = 480,     pointsize = 12, bg = "white", res = NA, ...) {    Cairo(width, height, type = "png", file = filename, pointsize = pointsize,         bg = bg, ...)}

This tells you that CairoPNG takes filename=... as a parameter, and passes this to Cairo as the file parameter.

I can see how this can lead to confusion, but the point is that your call to CairoPNG should be:

CairoPNG(filename="graphs.png")

See if that works...