user1172468
user1172468

Reputation: 5464

Unable to suppress messages from knitr

The following code still results in

```{r echo=FALSE, warning=FALSE}
rm(list=ls())
library(randomForest)
library(tree)
library(ggplot2)
```

the following -- how can I suppress the following?

## randomForest 4.6-12

## Type rfNews() to see new features/changes/bug fixes.

##
## Attaching package:'ggplot2'

## The following object is masked from'package:randomForest':
##
##     margin

Upvotes: 1

Views: 611

Answers (2)

Mikuana
Mikuana

Reputation: 634

In my opinion it's best to avoid blanket suppression of messages or warnings because its very easy to miss real issues that you do want to be warned about. I recommend disabling package load messages selectively on each package load. This way if you add a new package to your library list, you will see any errors or messages that are generated and have the choice to suppress them or deal with them in another way.

```{r echo=FALSE}
rm(list=ls())
suppressMessages(library(randomForest))
library(tree)
suppressMessages(library(ggplot2))
```

Upvotes: 2

neilfws
neilfws

Reputation: 33782

You can add message=FALSE:

```{r echo=FALSE, warning=FALSE, message=FALSE}

If that doesn't work, the package author is (incorrectly) using something other than message() for messages.

Upvotes: 2

Related Questions