How do I prevent Rplots.pdf from being generated?

rjzii picture rjzii · Jun 30, 2011 · Viewed 12.8k times · Source

I am working with some R code that generates a number of images as png files; however, a Rplots.pdf file keeps on being generated in the working directory, is there a way to prevent this from happening?

library(Cairo)
CairoPNG(file = "graphs.png")
nf <- layout(matrix(c(1:8), 2, 4, byrow=T), c(1, 1), c(1, 1, 1, 1), TRUE)
for (k in 1:num.k) {
    plotMatrix(connect.matrix.ordered[k,,], log = F, main = paste("k=", k.vector[k]), sub = paste("Cophenetic coef.=", rho[k]), ylab = "samples", xlab ="samples")
}
y.range <- c(1 - 2*(1 - min(rho)), 1)
plot(k.vector, rho, main ="Cophenetic Coefficient", xlim=c(k.init, k.final), ylim=y.range, xlab = "k", ylab="Cophenetic correlation", type = "n")
lines(k.vector, rho, type = "l", col = "black")
points(k.vector, rho, pch=22, type = "p", cex = 1.25, bg = "black", col = "black")
dev.off()

Answer

Syamanthaka picture Syamanthaka · Jul 27, 2016

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.