Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Silence messages about masked functions

Tags:

r

knitr

I'm trying to silence messages that explain that certain functions were masked by other packages. I have tried different combinations, but none delivered what I need.

The chunk I have is:

<<loadpkgs, echo=FALSE, warning=FALSE, message=FALSE>>=
suppressPackageStartupMessages(library(doMC))
suppressPackageStartupMessages(library(aroma.affymetrix))
suppressPackageStartupMessages(library(crlmm))
suppressPackageStartupMessages(library(snpStats))
suppressPackageStartupMessages(library(pd.genomewidesnp.6))
suppressPackageStartupMessages(library(GenomicRanges))
suppressPackageStartupMessages(library(ggbio))
@ 

But the output (which I hoped to be none) is (on the resulting PDF):

## Loading required package:  foreach
## foreach:  simple, scalable parallel programming from Revolution Analytics
## Use Revolution R for scalability, fault tolerance and more.
## http://www.revolutionanalytics.com
## Loading required package:  iterators
## Loading required package:  parallel
## Loading required package:  R.utils
## Loading required package:  R.oo
## Loading required package:  R.methodsS3
## R.methodsS3 v1.5.2 (2013-10-06) successfully loaded.  See ?R.methodsS3 for help.
## R.oo v1.15.8 (2013-10-10) successfully loaded.  See ?R.oo for help.
##
## Attaching package:  ’R.oo’
##
## The following objects are masked from ’package:methods’:
##
##    getClasses, getMethods

Any thoughts on how to solve this?

like image 826
benilton Avatar asked Dec 02 '13 02:12

benilton


2 Answers

Setting the parameter warn.conflicts=FALSE in library() as in

library(dplyr, warn.conflicts=FALSE)

should do the trick. This is particularly useful with parallel computing when potentially hundreds or more cores are loading the library.

like image 144
George Ostrouchov Avatar answered Oct 01 '22 19:10

George Ostrouchov


To get rid of the "Loading ..." messages use quietly=TRUE in the library call (and continue to use the suppressPackageStartupMessages):

suppressPackageStartupMessages(library(gdata, quietly=TRUE))

If you want to make this more compact, perhaps:

pkgs <-c('gdata', 'doMC', 'aroma.affymetrix', 'crlmm', 'snpStats', 
         'pd.genomewidesnp.6', 'GenomicRanges','ggbio')
for(p in pkgs) suppressPackageStartupMessages(library(p, quietly=TRUE, 
                                                      character.only=TRUE))

Might be safer to do some sort of test if you are going to suppress the "loading messages".

for(p in pkgs) suppressPackageStartupMessages( stopifnot( 
                                               library(p, quietly=TRUE, 
                                                        logical.return=TRUE, 
                                                        character.only=TRUE)))
like image 26
IRTFM Avatar answered Oct 01 '22 20:10

IRTFM