R语言 如何在针织物的末端显示针织物的整体效果

bsxbgnwa  于 2023-03-15  发布在  其他
关注(0)|答案(2)|浏览(83)

我在R中遇到了一个编织问题。如果一个块有一些东西需要打印,那么这个块会被分成两部分,结果会显示在每段代码下面,如下图所示:

所以,我希望每个结果都显示在块的最后,有没有办法做到这一点?
如下所示:

```{r echo=T, eval=FALSE}
message("hello")
message("world")

## hello
## world


非常感谢。
shyt4zoc

shyt4zoc1#

使用collapse=TRUE,记录如下:https://yihui.org/knitr/options/#code-evaluation网站。

---
title: hello
---

```{r blockname}
message("hello")
message("world")

![](https://i.stack.imgur.com/hpWTg.png)

title: hello

message("hello")
message("world")

![](https://i.stack.imgur.com/29Jjy.png)

由于需要更改R显示内容的方式(命令后的输出),因此我们需要借用[previous answer of mine](https://stackoverflow.com/a/30243074/3358272):

title: hello

message("hello")
message("world")

![](https://i.stack.imgur.com/4Xe60.png)
wgxvkvu9

wgxvkvu92#

很简单,你只需要设置一个块选项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)

相关问题