I noticed that some library comment manage to pass through the knitr options, with R 3.0.1 and knitr 1.5 running on Mac OSX 10.8.5. The following MWE



<<libraries, echo=FALSE, cache=TRUE, warning=FALSE, results='hide', cache.lazy=FALSE, message=FALSE>>=


will still produce in the output

enter image description here

Is there any way to silence unequivocally and universally the libraries?

NOTE: I think it could be an issue related to how knitr manage the warning messages from R. In this specific case the warning message was successfully suppressed but not the annotation preceding the message.

  • 2
    I cannot reproduce on R 3.0.2 with knitr 1.5 on Ubuntu (in other words, the output is empty as expected). In your posts it is always helpful if you give the versions of the software involved in your issue. What versions of knitr and R are you using? What is the output of the 'knit' comand when you run it (there might be warnings)? – scottkosty Jan 5 '14 at 11:10
  • I have a warning from the library memisc when I run the script in terminal. Warning message: package ‘memisc’ was built under R version 3.0.2 just after the very same lines that are also outputted when typesetting the PDF (# Loading required...) – Francesco Jan 5 '14 at 11:30
  • @scottkosty I edited the question with R and knitr version – Francesco Jan 5 '14 at 11:34
  • thanks. You added good info. However at this point I'm not sure your question is a question. You might want to rephrase it (e.g. "Why does knitr do this... on R 3.0.1?") or if you think it is a bug, report it – scottkosty Jan 5 '14 at 12:32
  • 1
    I can't reproduce either. I would try cleaning out your cache directory ... – Ben Bolker Jan 5 '14 at 16:27

Following Yihui's advice, I found the best option to be to invoke the warning=F and message=F chunk options, like so:

```{r, message=F, warning=F}

This was using knitr ("Knit HTML") with RStudio to process R markdown.

  • Better is include = FALSE. – Artem Klevtsov Mar 12 '16 at 5:05
  • These two don't work for me. Also ''include = FALSE'' doesn't show the results (plots). – PM0087 Jan 15 '20 at 8:34

Try the following code:

library(memisc, warn.conflicts = FALSE, quietly=TRUE)


suppressMessages(library(memisc, warn.conflicts = FALSE, quietly=TRUE))
  • 2
    in theory, that is not necessary after you use the chunk option message=FALSE – Yihui Xie Jan 6 '14 at 1:56
  • But if your writing an Rscript, as opposed to Rmarkdown, this is what you need. – DryLabRebel May 18 at 23:24

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.