在Knitr/Rmarkdown中抑制消息 [英] Suppressing messages in Knitr / Rmarkdown
问题描述
这是我的RMarkdown文件的代码:
Here is the code for my RMarkdown file:
```{r echo=FALSE, message=FALSE}
opts_chunk$set(comment = NA, echo=FALSE, message = FALSE, warnings = FALSE)
options("getSymbols.warning4.0"=FALSE)
Sys.setenv(TZ = "GMT")
library(quantmod)
library(xtable)
library(PerformanceAnalytics)
```
```{r}
getSymbols("^RUT")
chart.TimeSeries(RUT)
dev.off()
```
尽管设置为message = FALSE, warnings = FALSE
,但运行getSymbols()
和dev.off()
时仍在HTML文件中获取输出消息.它们各自的输出是:
Despite settings message = FALSE, warnings = FALSE
, I am still getting output messages in the HTML file when I run getSymbols()
and dev.off()
. Their respective outputs are:
[1] "RUT"
和
null device
1
如何隐藏这些消息?
推荐答案
尝试使用invisible
禁止显示这些类型的输出.
Try using invisible
to suppress those types of output.
```{r}
invisible(getSymbols("^RUT"))
chart.TimeSeries(RUT)
invisible(dev.off())
```
从?invisible
的帮助页面:
当需要具有可以分配的返回值但未分配时不打印的函数时,此函数很有用.
This function can be useful when it is desired to have functions return values which can be assigned, but which do not print when they are not assigned.
这些都不是消息"或警告",而是实际输出值.您会看到
Neither of these are "messages" or "warnings", but actual output values. You'll see that the messages for getSymbols
are, indeed, suppressed by knitr in the output.
这篇关于在Knitr/Rmarkdown中抑制消息的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!