如何在加载库时禁止显示警告消息?

时间:2013-09-21 09:23:26

标签: r

我正在尝试从命令行运行r脚本,但是在加载包时会收到警告消息:

C:\Temp>Rscript myscript.r param
Warning message:
package 'RODBC' was built under R version 3.0.1
Warning message:
package 'ggplot2' was built under R version 3.0.1
Warning message:
package 'reshape2' was built under R version 3.0.1
Warning message:
package 'lubridate' was built under R version 3.0.1
Warning message:
package 'scales' was built under R version 3.0.1

我尝试使用suppressPackageStartupMessages

suppressPackageStartupMessages(library(RODBC))

supressMessages

suppressMessages(library(RODBC))

但这些并没有压制这些消息。如何摆脱这些警告?

2 个答案:

答案 0 :(得分:44)

这些不是消息而是警告。你可以这样做:

suppressWarnings(library(RODBC))

suppressWarnings(suppressMessages(library(RODBC)))

禁止这两种类型。

答案 1 :(得分:9)

我将其放在所有脚本的顶部,并在我的库加载前言:

shhh <- suppressPackageStartupMessages # It's a library, so shhh!

然后您可以这样加载库:

shhh(library(tidyverse))

并依靠完美的沉默。