pidosaurus pidosaurus - 3 months ago 17
R Question

How can I call ggsave without producing any output like `Saving 7 x 7 in image`?

I try to suppress the

Saving 7 x 7 in image
output of
ggsave()
whenever I run it, but it seems impossible. Is this possible? How to do it?

I have tried the following, but nothing works:


  • capture.output()

  • sink()

  • changing the warnings option

  • assign it to a variable



Minimal ``working'' example:

librrary(ggplot2)
df <- data.frame(gp = factor(rep(letters[1:3], each = 10)),
y = rnorm(30))
plot.to.be.saved <- ggplot(df) + geom_point(aes(x = gp, y = y))
sink('/dev/null')
ggsave(filename = '~/.so.pdf', plot = plot.to.be.saved)
sink()
# Saving 7 x 7 in image

options(warn=-1)

no.output.please <- ggsave(filename = '~/.so.pdf', plot = plot.to.be.saved)
# Saving 7 x 7 in image
capture.output(ggsave(filename = '~/.so.pdf', plot = plot.to.be.saved), file = 'NUL')
# Saving 7 x 7 in image

Answer

ggplot2:::plot_dim issues this as a message, so suppressMessages(ggsave("test.pdf", ggplot())) should do.