Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
213 views
in Technique[技术] by (71.8m points)

r - Disable messages upon loading a package

I have a package in R (ROCR) that I need to load in my R environment. Upon loading the package, a set of messages are printed. This is ordinarily fine, but since the output of my R script is being used for further analysis I want to completely disable all of this output. How do I do that? Furthermore, I'd prefer to do it without having to modify ROCR at all, so that future users of this script don't have to do that either.

So far:

  • sink() doesn't work here - redirecting both stdout and std err to /dev/null does nothing for me.
  • Unsurprisingly, options(warnings=-1) does nothing either, since these are not warnings, per se, being printed.

Any thoughts?

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

Just use suppressMessages() around your library() call:

edd@max:~$ R

R version 2.14.1 (2011-12-22)
Copyright (C) 2011 The R Foundation for Statistical Computing
ISBN 3-900051-07-0
Platform: x86_64-pc-linux-gnu (64-bit)
[...]

R> suppressMessages(library(ROCR))
R>                                               # silently loaded
R> search() 
 [1] ".GlobalEnv"         "package:ROCR"         # it's really there      
 [3] "package:gplots"     "package:KernSmooth"
 [5] "package:grid"       "package:caTools"   
 [7] "package:bitops"     "package:gdata"     
 [9] "package:gtools"     "package:stats"     
[11] "package:graphics"   "package:grDevices" 
[13] "package:utils"      "package:datasets"  
[15] "package:methods"    "Autoloads"         
[17] "package:base"      
R> 

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...