dev='png' is not working for pdf output in knitr

人盡茶涼 提交于 2020-01-04 04:04:12

问题


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:


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.



来源:https://stackoverflow.com/questions/28954647/dev-png-is-not-working-for-pdf-output-in-knitr

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!