【问题标题】:knitr shows comments from library importknitr 显示来自库导入的评论
【发布时间】:2014-07-19 07:24:24
【问题描述】:

我有一个小的 Rnw 文件。使用 knitr 编译时,它显示在 pdf 中导入 cmets。如何删除这些 cmets?这是文件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}

当我用 knitr 编译时

$ Rscript -e "library(knitr); knit('a.Rnw')"

我在 tex 文件中得到了这个无关的位:

\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} 

显示为

这正常吗?如何删除这些 cmets?

【问题讨论】:

标签: r knitr rnw


【解决方案1】:

最简单的做法是将message=FALSE 放入您的块选项中,可以是本地的该块,也可以通过靠近文档头部的library(knitr); opts_chunk$set(message=FALSE)

这比@rawr links to in the comments above 的问题要简单一些,因为它指的是一个行为不端的包,它使用cat() 而不是message() 作为其启动消息。 message=FALSE 将抑制 所有 块产生的消息;如果你想更精确一点

suppressPackageStartupMessages(library(earth))

应该可以,但我发现 message=FALSE 通常是无害的,而且看起来更漂亮(例如,如果你想要 echo=TRUE 代替)。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2021-10-28
    • 2019-12-07
    • 1970-01-01
    • 1970-01-01
    • 2013-06-05
    • 2017-03-19
    • 1970-01-01
    • 2016-05-14
    相关资源
    最近更新 更多