从编织器输出中删除进度条

Mtr*_*tra 7 r knitr r-markdown

我正在分析一些数据,并想在R上做一个Simpsons悖论。我已经安装了Simpsons包并加载了库。这是一个基于软件包文档的示例:

---
output: html_document
---
```{r}
library(Simpsons)
#generating data 
Coffee1=rnorm(100,100,15)
Neuroticism1=(Coffee1*.8)+rnorm(100,15,8)
g1=cbind(Coffee1, Neuroticism1)
Coffee2=rnorm(100,170,15)
Neuroticism2=(300-(Coffee2*.8)+rnorm(100,15,8))
g2=cbind(Coffee2, Neuroticism2)
Coffee3=rnorm(100,140,15)
Neuroticism3=(200-(Coffee3*.8)+rnorm(100,15,8))
g3=cbind(Coffee3, Neuroticism3)
data2=data.frame(rbind(g1,g2,g3))
colnames(data2) <- c("Coffee","Neuroticism")

example <- Simpsons(Coffee,Neuroticism,data=data2) 
plot(example)
```
Run Code Online (Sandbox Code Playgroud)

这将返回一个包含3个簇的图(正是我所需要的)。但是,当我将Rmd文件编织为HTML时,会得到很多等号(======),其旁边有一个百分比,例如一个加载网格,我想从最终输出中删除该网格。

在此处输入图片说明

Mic*_*per 6

您可以通过设置 knitr 块选项来抑制 R 中的任何输出消息。如果我们希望隐藏除绘图以外的所有代码输出,我们可以使用以下解决方案

---
output: html_document
---

```{r echo=FALSE, results='hide', fig.keep='all', message = FALSE}
library(Simpsons)
#generating data 
Coffee1=rnorm(100,100,15)
Neuroticism1=(Coffee1*.8)+rnorm(100,15,8)
g1=cbind(Coffee1, Neuroticism1)
Coffee2=rnorm(100,170,15)
Neuroticism2=(300-(Coffee2*.8)+rnorm(100,15,8))
g2=cbind(Coffee2, Neuroticism2)
Coffee3=rnorm(100,140,15)
Neuroticism3=(200-(Coffee3*.8)+rnorm(100,15,8))
g3=cbind(Coffee3, Neuroticism3)
data2=data.frame(rbind(g1,g2,g3))
colnames(data2) <- c("Coffee","Neuroticism")

example <- Simpsons(Coffee,Neuroticism,data=data2) 
plot(example)
```
Run Code Online (Sandbox Code Playgroud)

我会注意到这个包似乎比大多数包打印出更多的内容,因此选项的组合很长。

一个更简单的方法可能是将绘图移动到一个单独的块,并在它之前运行所有分析。该include参数可用于抑制所有输出,但这包括绘图,因此我们必须使用两个块:

```{r, include = FALSE}
# your code to build model
```

```{r}
plot(example)
```
Run Code Online (Sandbox Code Playgroud)

在此处查看 knitr 块选项的完整列表