einar
einar

Reputation: 473

Call plot() in R without producing a plot

I have written some plot methods that I want to do automated unit tests on in R with testthat. Doing so fills my test script folder with plot files, which is a nuisance.

My Q: is there a way to plot to a device that just throws the plot away? Sort of like writing a file to /dev/null

Upvotes: 1

Views: 71

Answers (1)

Roland
Roland

Reputation: 132706

From help("pdf"):

file: a character string giving the name of the file. If it is of the form "|cmd", the output is piped to the command given by cmd. If it is NULL, then no external file is created (effectively, no drawing occurs), but the device may still be queried (e.g., for size of text).

Thus,

pdf(file = NULL)
plot(1)
dev.off()

doesn't produce any output.

Upvotes: 5

Related Questions