我正在使用 RStudio 0.98.932 和 knitr 1.6。想为 word 和 html 设置不同的全局 knitr 选项。例如,想将 fig.width 和 fig.height 设置为 word 为 6,html 为 11。
如果它可用于 rmd 文件的输出格式,我可以编写一些代码来切换设置。我该怎么做?感谢您的任何建议。
最佳答案
尝试将此代码块放在 Rmd 文档的开头。
```{r setup, cache=FALSE, include=FALSE}
library(knitr)
output <- opts_knit$get("rmarkdown.pandoc.to")
if (output=="html") opts_chunk$set(fig.width=11, fig.height=11)
if (output=="docx") opts_chunk$set(fig.width=6, fig.height=6)
```
opts_knit$get()
返回的包选项之一是 markdown.pandoc.to
.这显然设置为 "html"
, "docx"
, 或 "latex"
取决于所选的输出格式(HTML、Word 或 PDF)。所以你可以测试它并设置 block 选项fig.width
和 fig.height
因此。
关于r - 如何在 knitr 和 RStudio 中为 word 和 html 设置不同的全局选项?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/25236850/