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)
```
Specs: Max OS 10.11, R version 3.2.0 (2015-04-16), RStudio 0.98.1062, knitr 1.12.3
knitr is an engine for dynamic report generation with R. It is a package in the programming language R that enables integration of R code into LaTeX, LyX, HTML, Markdown, AsciiDoc, and reStructuredText documents. The purpose of knitr is to allow reproducible research in R through the means of literate programming.
The first code chunk: ```{r setup, include=FALSE} knitr::opts_chunk$set(echo = TRUE) ``` is used to specify any global settings to be applied to the R Markdown script. The example sets all code chunks as “echo=TRUE”, meaning they will be included in the final rendered version.
The following sections dive into the three components of an R Markdown document in more details: the markdown text, the code chunks, and the YAML header.
Chunk Options include = FALSE prevents code and results from appearing in the finished file. R Markdown still runs the code in the chunk, and the results can be used by other chunks. echo = FALSE prevents code, but not the results from appearing in the finished file. This is a useful way to embed figures.
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With