Kwangi
Kwangi

Reputation: 29

"Error in png(..., res = dpi, units = "in")" while running Knit to html in R Studio

I am getting an error message while running knit to HTML. But If I run chunk individually, it draws plot as expected. What would be a problem? The error message is below:

Quitting from lines 270-274 (HC_FC_indivisual_cellline_fdr_1%.Rmd) Error in png(..., res = dpi, units = "in") : invalid 'filename' Calls: ... in_dir -> plot2dev -> do.call -> -> png Execution halted

Upvotes: 2

Views: 2552

Answers (3)

Negin17h
Negin17h

Reputation: 1

I had the same problem. I updated R to the latest version and also RStudio. Install the required packages for the knit and then everything became fine. Adding 'dev.off()' can solve the problem for knitting but will cause another problem and does not show the plots in the HTML file.

Upvotes: 0

Gregor Kvas
Gregor Kvas

Reputation: 161

The described error also occurs, when you are knitting plots within named code chunks, and the name of the chunk does not lead to a valid path name during knitting process.

That is, during the knitting process the plots are written into a temporary path which contains the name of the code chunk, ergo this name should contain only characters that are valid for path names. One should avoid to use white characters for chunk names as well.

Upvotes: 7

Benjamin Booker
Benjamin Booker

Reputation: 29

I ran into the same issue. I ran this right before my first plot in the chunk and it solved it for me

dev.off()

hope this helps.

Upvotes: 1

Related Questions