Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

R suppress startupMessages from dependency

Tags:

r

One of my R package's dependencies displays startup messages when loaded. I would like to suppress these startup messages.

The only fix I found so far was removing the offending package from the Depends: line in my DESCRIPTION file. Then calling suppressPackageStartupMessages(require("offendingPackage")) in .onLoad of my package.

I would rather keep the offending package as part of my Depends, but it seems that anything specified in depends is automatically loaded and therefore can't be supressed.

like image 642
Nick Avatar asked Jun 08 '11 13:06

Nick


2 Answers

The suppressPackageStartupMessages() function works if and only if the startup messages are actually written with packageStartupMessage() -- see the help page.

Many packages just use cat(), which one could consider a buglet. In that case

 suppressMessages(library(foo))

works better.

like image 164
Dirk Eddelbuettel Avatar answered Nov 14 '22 09:11

Dirk Eddelbuettel


If you work with namespaces, you can specify the package in Imports, and load the necessary functions using import or importFrom. This way, the package is not attached, but the necessary functions can be loaded and used by your package. Without attaching, the startup messages are not given, so this approach assures you won't see any startup messages of packages specified in Imports.

Make sure you check that you imported everything that is of importance. If the package you import is dependent on other packages, I'm not sure everything you need to use those functions is imported. You might have to do a bit of puzzling to get everything you need loaded. On the plus side, using Imports assures that any dependencies check will be carried out correctly.

Another option is to not specify the package in Depends, but in Suggests in the DESCRIPTION file, and use the option @Dirk gave you. This will give a correct dependency check if 'dependencies=TRUE' is set in install.packages(). But personally I think using the namespaces is a lot more clean.

like image 40
Joris Meys Avatar answered Nov 14 '22 11:11

Joris Meys