简体   繁体   中英

How to remove dev.off() phrasing from the pdf output?

I am creating a pdf file where I am "printing" a png with grid.draw() since it was a merge of two plots, therefore impossible to use ggsave since it was not a plot.

Anyways, when printing the result, everything is fine except the message from dev.off(). The console is as it follows:

# saving grid draw to a png (not a ggplot class, therefore other kind of saving is needed)
> png(filename = "data_x_plot.png",
+         pointsize = 500, 
+         width = 1200,
+         height = 1000,
+         units = "px") 
> grid.draw(data_x)
> dev.off()
RStudioGD 
        2 

And the code in the .Rnw script is as follows:

g1 <- ggplotGrob(p1)
g2 <- ggplotGrob(p2)
data_x <- rbind(g1, g2, size="first") # stack the two plots
data_x$widths <- unit.pmax(g1$widths, g2$widths) # use the largest widths

# saving grid draw to a png (not a ggplot class, therefore other kind of saving is needed)
png(filename = "data_x_plot.png",
    pointsize = 500, 
    width = 1200,
    height = 1000,
    units = "px") 
grid.draw(data_x)
dev.off()
@
  
  \begin{center}
\includegraphics[scale=0.37]{data_x_plot.png}
\captionof{figure}{Overview of the x data.}
\end{center}

Strangely, what is being printed to the pdf before each png.file is not "RStudioGD 2" , but "pdf 2" . I do not what "RStudioGD 2" to be printed out... I just want that this kind of messages do not pass to the pdf file.

Can you tell me how to avoid or how to hide this message from dev.off()?

As Rui Barradas, said in the comments, the solution is just replace the

dev.off()

by

invisible(capture.output(dev.off()))

Very easy solution to omit any message created by annoying functions.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM