3
votes

In the default setting, knitr will use "'pdf' for LaTeX output and 'png' for HTML/markdown". However, I can specify the dev = "png" in the chunk options for the LaTeX output. This feature is very useful to reduce the file size for big vector figure (e.g. maps).

In the previous version of knitr (could be 1.8.*, but not sure), I can specify the dev = "png" (the example below is working for earlier version).

Today I installed the latest version of knitr from github (just now). But the dev='png' is not working for pdf output. I have to use png device for pdf output as I have some big vector figure in pdf format.

The error message is:

 Error in (function (filename = "Rplot%03d.png", width = 480, height = 480, :
 unused argument (pdf = list(useDingbats = FALSE) Call: <Anonymous> ...
 block_exec -> chunk_device -> dev_new -> do.call -> <Anonymous> Execution halted))

How could I fix this problem?

This is my example:

---
output: pdf_document
---


```{r, echo=FALSE, dev='png'}
plot(cars)
```

Thanks for any advice. Please let me know if my question is still not clear.

This is my session information.

R version 3.1.3 (2015-03-09)
Platform: x86_64-w64-mingw32/x64 (64-bit)
Running under: Windows 7 x64 (build 7601) Service Pack 1

locale:
[1] LC_COLLATE=English_Australia.1252  LC_CTYPE=English_Australia.1252    LC_MONETARY=English_Australia.1252
[4] LC_NUMERIC=C                       LC_TIME=English_Australia.1252    

attached base packages:
[1] stats     graphics  grDevices utils     datasets  methods   base     

other attached packages:
[1] knitr_1.9.4

loaded via a namespace (and not attached):
[1] digest_0.6.4    evaluate_0.5.5  formatR_1.0     htmltools_0.2.6 rmarkdown_0.5.1 stringr_0.6.2  
[7] tools_3.1.3     yaml_2.1.13    
1
The preamble of this question is not making a lot of sense to me. Can you explain why you expect dev='png' [to "work"] for pdf. What would the verb "work" mean in this context?IRTFM

1 Answers

4
votes

This is a bug in knitr. I just fixed it in the development version (v1.9.5). The reason for the failure was that the options for the pdf device were passed to the png device.