我如何抑制这个输出? [英] How do I suppress this output?
问题描述
我在 R Markdown 文件中有一个代码块.
I have a code chunk in an R Markdown file.
```{r}
library(UsingR)
```
使用 knitHTML 编译会导致以下输出,这在我更新到最新版本的 R 和 RStudio 之前从未发生过:
Using knitHTML to compile causes the following output, which never happened before I updated to the latest versions of R and RStudio:
## Loading required package: MASS
## Loading required package: HistData
## Loading required package: Hmisc
## Loading required package: grid
## Loading required package: lattice
## Loading required package: survival
## Loading required package: splines
## Loading required package: Formula
##
## Attaching package: 'Hmisc'
##
## The following objects are masked from 'package:base':
##
## format.pval, round.POSIXt, trunc.POSIXt, units
##
## Loading required package: aplpack
## Loading required package: tcltk
## Loading required package: quantreg
## Loading required package: SparseM
##
## Attaching package: 'SparseM'
##
## The following object is masked from 'package:base':
##
## backsolve
##
##
## Attaching package: 'quantreg'
##
## The following object is masked from 'package:Hmisc':
##
## latex
##
## The following object is masked from 'package:survival':
##
## untangle.specials
##
##
## Attaching package: 'UsingR'
##
## The following object is masked from 'package:survival':
##
## cancer
我怎样才能抑制这个输出?注意:echo=FALSE 不起作用.
How can I suppress this output? Note: echo=FALSE did not work.
推荐答案
在代码块中设置 message=FALSE
应该可以工作.
Setting message=FALSE
in your code chunk should work.
```{r, message=FALSE}
library(UsingR)
```
设置 echo=FALSE
不应该起作用 - 这是设计使然.代码块中的 echo
参数控制代码块内代码的显示(即 library(UsingR)
).
Setting echo=FALSE
should not have worked - this is by design. The echo
parameter in the code chunk controls the display of the code inside the chunk (i.e. library(UsingR)
).
消息(如图所示)通过message
参数单独处理.
Messages (as shown) are handled separately through the message
parameter.
错误通过 error
参数处理(即 error=FALSE
将抑制错误消息).
Errors are handled through the error
parameter (i.e. error=FALSE
will suppress error messages).
结果通过 results
参数处理(即 results=FALSE
将抑制代码块的结果).
Results are handled through the results
parameter (i.e. results=FALSE
will suppress the results of the code chunk).
警告通过 warning
参数处理(即 warning=FALSE
将抑制代码块生成的警告),因为警告与错误不同.
Warnings are handled through the warning
parameter (i.e. warning=FALSE
will suppress the warnings generated by the code chunk) as warnings are distinct from errors.
还有许多其他代码块参数可用,但这些是控制给定代码块生成的基于文本的输出的主要参数.
There are many other code-chunk parameters available, but these are the main parameters governing the text-based output generated by a given code-chunk.
这篇关于我如何抑制这个输出?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!