Using jpeg (file =) creates an empty jpeg even if there is no call to generate the graph

This is observed in the party. Considering the following code snippet, I don't understand why R creates an empty jpeg file on Windows, even though I am not naming a graph or graph. When I run similar code under Linux or OS X, no jpeg file is generated. I don't know in advance if the user wants to plot, so I set the filename in advance and give them a name and location.

norm <- rnorm(100)


Any suggestions would be appreciated.


source to share

2 answers

The help file ?jpeg

(which also applies to devices bmp()

, png()

and tiff()

) indicates that:

The โ€˜type = "windows"โ€™ versions of these devices effectively plot
 on a hidden screen and then copy the image to the required format.


This Windows-specific implementation detail most likely explains the difference in behavior between Windows and * NIX systems.

On Windows, calling any of the above functions (and pdf()

and postscript()

) creates a file --- regardless of whether you draw anything on that hidden screen. Except for pdf()

(which creates files that I cannot open with the viewer), the image registered to the build device is a white rectangle of height and width specified when the specific device is called.



I wouldn't bother with that. if the prospect of zero-length files cluttering a folder bothers you, you can clean up after which something like

jpgs <- file.path("c:/temp", dir(pattern="c:/temp/test[0-9]*\\.jpeg"))
s <-[["size"]]
for(i in seq_along(s))
    if(s[i] == 0) file.remove(jpgs[i])




All Articles