knitr icon indicating copy to clipboard operation
knitr copied to clipboard

Graphs not rendering in PDF when using dev.new() with knitr

Open Higgs32584 opened this issue 7 months ago • 3 comments

Screenshot 2024-07-09 120145 Screenshot 2024-07-09 120128 Screenshot 2024-07-09 120101

Hi, so recently, I was using knitr to compile graphs for my homework and, I was adding dev.new() before all of my graphs, as I thought this was the normal format to create graphs in. What did end up happening though, is that graphs that followed dev.new() did not render at all in the pdf. while I understand dev.new is a function in the graphics package, I ran into no issues when compiling the graphs in markdown, as they all displayed perfectly fine, the code interaction seems to be related specifically towards how knitr compiles .rmd into a .pdf.

A warning label related to instances of dev.new() in the compilation would be ideal, as I imagine taking into account new graph windows might be too complex.

library("robustbase")
data("coleman",package="robustbase")
dev.new()
barplot(salaryP ~ fatherWc,data=coleman)
dev.new()
plot(salaryP ~ fatherWc,data=coleman)

Higgs32584 avatar Jul 09 '24 16:07 Higgs32584