从 knitr 输出中删除进度条

Remove progress bar from knitr output

我正在分析一些数据,想在 R 上做一个辛普森一家的悖论。我已经安装了 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)
```

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

您可以通过设置 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)
```

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

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

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

```{r}
plot(example)
```

Check out the full list of knitr chunk options here