Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Suppressing messages in Knitr / 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() ``` 

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" 

and

null device            1  

How do I suppress these messages?

like image 477
mchangun Avatar asked Mar 14 '13 09:03

mchangun


People also ask

How do I hide messages in R Markdown?

Hide source code: ```{r, echo=FALSE} 1 + 1 ``` Hide text output (you can also use `results = FALSE`): ```{r, results='hide'} print("You will not see the text output.") ``` Hide messages: ```{r, message=FALSE} message("You will not see the message.") ``` Hide warning messages: ```{r, warning=FALSE} # this will generate ...

How do I hide error messages in R?

As suggested by the previous solution, you can use try or tryCatch functions, which will encapsulate the error (more info in Advanced R). However, they will not suppress the error reporting message to stderr by default. This can be achieved by setting their parameters. For try , set silent=TRUE .

What is knitr in R Markdown?

knitr is an engine for dynamic report generation with R. It is a package in the programming language R that enables integration of R code into LaTeX, LyX, HTML, Markdown, AsciiDoc, and reStructuredText documents. The purpose of knitr is to allow reproducible research in R through the means of literate programming.


2 Answers

Ran into this problem as well, I would like to add that it should be warning = FALSE, not warnings = FALSE

like image 136
user190477 Avatar answered Sep 25 '22 09:09

user190477


You should never need to use dev.off() when using knitr. It takes care of all the devices to create plots.

From the package author Yihui

God kills a kitten whenever you dev.off()

null device            1  

Is the output of dev.off().

It may be that getSymbols returns something given that you haven't defined env

If you want to hide the results (output) (in general) you can use results = 'hide' as an option. No need to wrap anything in invisible()

like image 29
mnel Avatar answered Sep 24 '22 09:09

mnel