我在R中遇到了一个编织问题。如果一个块有一些东西需要打印,那么这个块会被分成两部分,结果会显示在每段代码下面,如下图所示:
所以,我希望每个结果都显示在块的最后,有没有办法做到这一点?如下所示:
```{r echo=T, eval=FALSE} message("hello") message("world")
## hello ## world
非常感谢。
shyt4zoc1#
使用collapse=TRUE,记录如下:https://yihui.org/knitr/options/#code-evaluation网站。
collapse=TRUE
--- title: hello --- ```{r blockname} message("hello") message("world")
![](https://i.stack.imgur.com/hpWTg.png)
message("hello") message("world")
![](https://i.stack.imgur.com/29Jjy.png) 由于需要更改R显示内容的方式(命令后的输出),因此我们需要借用[previous answer of mine](https://stackoverflow.com/a/30243074/3358272):
![](https://i.stack.imgur.com/4Xe60.png)
wgxvkvu92#
很简单,你只需要设置一个块选项results = "hold"。例如:
results = "hold"
knitr::opts_chunk$set(echo = TRUE, results = "hold")
X = rnorm(100, 100, 15) Y = rnorm(100, 100, 20) mean(Y+X) mean(Y)+mean(X)
2条答案
按热度按时间shyt4zoc1#
使用
collapse=TRUE
,记录如下:https://yihui.org/knitr/options/#code-evaluation网站。title: hello
title: hello
wgxvkvu92#
很简单,你只需要设置一个块选项
results = "hold"
。例如: