问题描述
在我的R Markdown文档中设置全局选项时遇到麻烦.下面是一个简单的示例.在这种情况下,我尝试设置global.par = TRUE
.期望将我在一个卡盘中所做的任何par()
规格都携带到后续块中.但是,这没有发生.
I am having trouble with setting global options in my R Markdown documents. A simple example follows. In this case I've attempted to set global.par = TRUE
. The expectation is that any par()
specifications I make in one chuck are carried into subsequent chunks. However, this is not happening.
```{r package_options, include=FALSE}
knitr::opts_knit$set(global.par = TRUE)
```
```{r}
lambda <- 0.2; n <- 1000
exp <- rexp(n, lambda)
par(cex = 0.7)
hist(exp)
```
```{r}
lambda <- 0.02; n <- 1000
exp <- rexp(n, lambda)
hist(exp)
```
规格:Max OS 10.11,R版本3.2.0(2015-04-16),RStudio 0.98.1062,knitr 1.12.3
Specs: Max OS 10.11, R version 3.2.0 (2015-04-16), RStudio 0.98.1062, knitr 1.12.3
推荐答案
此问题已已修复在 knitr (> = v1.12.17)中,您可以测试当前的 Github上 knitr 的开发版本.我只是发现设置mfcol
/mfrow
会将cex
重置为1,这是 knitr 无法正确恢复cex
的根本原因.
This issue has been fixed in knitr (>= v1.12.17), and you may test the current development version of knitr on Github. I just discovered that setting mfcol
/mfrow
will reset cex
to 1, and that was the root cause of knitr not being able to restore cex
correctly.
这篇关于尊重Knitr中的全局选项的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!