[英]How to evaluate all chunks in Rmarkdown
How do I evaluate all of the chunks in an Rmd document, without putting eval=TRUE at each chunk? 如何评估Rmd文档中的所有块,而不是在每个块上放置eval = TRUE? The way I have it below, only the first chunk is evaluated.
我在下面的方式,只评估第一个块。
```{r,eval=TRUE}
1+1
```
Some text
```
2+2
```
EDIT: 编辑:
I'm trying to knit/compile to HTML. 我正在尝试编织/编译为HTML。
```
require(knitr)
opts_chunk$set(eval = TRUE, tidy = TRUE, cache = FALSE, echo = FALSE, include = FALSE,
fig.path = 'figures/', dev = c("pdf"),
fig.width = 7, fig.height = 7)
```
some text
```
1+1
```
more text
```
2+2
```
eval=TRUE
is the default behaviour for .Rmd chunks, so you shouldn't need to explicitly add it to your chunks' options. eval=TRUE
是.Rmd块的默认行为,因此您不需要将其显式添加到块的选项中。
However, you do need to include {r}
after your opening fences in order for the chunk to be recognised as R code and evaluated accordingly. 但是, 你需要包括
{r}
你为了打开围栏的块被识别为R代码和相应的后评价。 Chunks that do not open with ```{r}
will not be run, hence the problem you're seeing. 没有打开
```{r}
将无法运行,因此您遇到了问题。
A working example might be: 一个工作示例可能是:
```{r}
1+1
```
Some text
```{r}
2+2
```
To insert a new, empty chunk with the appropriate fences and {r}
, you can press Ctrl + Alt + i on Windows, or ⌘ + Option + i on Mac, or click this icon at the top right of the RStudio source pane (from memory, older versions of RStudio had an 'Insert' drop-down in that general area): 要插入带有相应栅栏和
{r}
的新空块,可以在Windows上按Ctrl + Alt + i ,或在Mac上按⌘ + Option + i ,或单击RStudio源窗格右上角的此图标(从内存来看,旧版本的RStudio在该常规区域中有一个“插入”下拉列表:
In your first chunk you can set knitr
options globally. 在您的第一个块中,您可以在全局设置
knitr
选项。
opts_chunk$set(tidy = TRUE, cache = FALSE, echo = FALSE, include = FALSE,
fig.path = 'figures/', dev = c("pdf"),
fig.width = 7, fig.height = 7)
In any subsequent chunk, you can change these by the usual means but they only apply to that chunk. 在任何后续块中,您可以通过常规方式更改它们,但它们仅适用于该块。
EDIT. 编辑。 Here is a fuller example from K. Broman
以下是K. Broman的更全面的例子
```{r global_options, include=FALSE}
knitr::opts_chunk$set(fig.width=12, fig.height=8, fig.path='Figs/',
echo=FALSE, warning=FALSE, message=FALSE)
```
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.