tumultous_rooster
tumultous_rooster

Reputation: 12560

How do I suppress the warning from including a library when using knitr in R?

I'm using knitr to generate HTML output of my work while using R.

The problem is, when I include a library, such as

library(car)

my R markdown document includes the warning:

## Warning: package 'car' was built under R version 2.15.3

I have tried these solutions, but none work:

```{r }
invisible(library(car)

and

```{r message = FALSE, warnings = FALSE}

along with

```{r results = 'hide'}

and unfortunately none of these options work.

Further options I've tried, and the actual knitr output follow:

enter image description here enter image description here enter image description here

How do I suppress the warning from including a library when using knitr in R?

Thanks in advance.

Upvotes: 22

Views: 22751

Answers (4)

Mariano
Mariano

Reputation: 21

Using message=FALSE in the chunk options do the job

Upvotes: 2

Bart
Bart

Reputation: 226

Set the following chunk options message=FALSE, warning=FALSE, include=FALSE.

Upvotes: 18

Dirk is no longer here
Dirk is no longer here

Reputation: 368399

My preferred approach is

suppressMessages(library(foo))

and if in doubt also load everything foo Depends on the same way.

A concrete example:

R> suppressMessages(library(KernSmooth))
R>

and I would invite those suggesting other methods to try on this one too. In this case, suppressPackageStartupMesssage() will work too.

Upvotes: 8

user3471268
user3471268

Reputation:

There's a direct way of doing this pretty easily, if you look at ?library:

library(car, quietly = TRUE)

It should eliminate most warnings and attachment messages quite nicely. If it doesn't work, add warn.conflicts = FALSE too.

Upvotes: 4

Related Questions