knitr shows comments from library import

knitr, r, rnw

Solution

The simplest thing to do is to put `message=FALSE` in your chunk options, either locally for that chunk or via `library(knitr); opts_chunk$set(message=FALSE)` near the head of your document.

This is a little bit simpler than the question that @rawr links to in the comments above, because that referred to a badly behaved package that used `cat()` rather than `message()` for its startup messages. `message=FALSE` will suppress all messages produced by the chunk; if you want to be a little bit more precise

suppressPackageStartupMessages(library(earth))

should work, but I find that `message=FALSE` is usually harmless enough, and looks prettier (e.g. if you wanted `echo=TRUE` instead).

Problem

I have a small Rnw file. When compiled with knitr, it shows importing comments in the pdf. How do I remove these comments? Here is the file a.Rnw: ``` \documentclass[10pt,a4paper]{article} \usepackage[latin1]{inputenc} \usepackage{amsmath} \usepackage{amsfonts} \usepackage{amssymb} \begin{document} Hi, this is an example! <<setup, echo=FALSE, cache=TRUE>>== library(earth, warn.conflicts=FALSE) a <- rnorm(100); b<- 0.05*rnorm(100) - .2*a model <- lm(a~b) plot(model) @ \end{document} ``` When I compile with knitr ``` $ Rscript -e "library(knitr); knit('a.Rnw')" ``` I get this extraneous bit in the tex file: ``` \definecolor{shadecolor}{rgb}{0.969, 0.969, 0.969}\color{fgcolor}\begin{kframe} {\ttfamily\noindent\itshape\color{messagecolor}{\#\# Loading required package: plotmo\\\#\# Loading required package: plotrix}}\end{kframe} ``` Which shows up as Is this normal? How do I remove these comments?

Original source

Related problems