这是我的RMarkdown文件的代码:
```{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文件中得到输出消息。它们各自的输出是:[1] "RUT"
和
null device
1
如何隐藏这些消息?
最佳答案
尝试使用invisible
禁止显示这些类型的输出。
```{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.
这些都不是“消息”或“警告”,而是实际输出值。您会看到
getSymbols
的消息确实在输出中被knitr抑制了。
关于r - 在Knitr/Rmarkdown中抑制消息,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/15406028/