[R] "Optional" package dependency

Peter Langfelder peter.langfelder at gmail.com
Mon May 24 22:58:15 CEST 2010


Hi all,

apologies if this has been answered before, I didn't find the answer
in the archives. I am putting together a package that I would like to
have optional functionality if another package is installed. In
normal, non-package code, I would simply write something like

if (require(qvalue))
{
   # use package qvalue
} else {
  # do not use package qvalue
}

If I do something like that in a package, I get warnings about using
undeclared imports.

In the DESCRIPTION file, I can specify the following fields:

Depends : not useful for this purpose

Imports : doesn't seem to be useful: if qvalue isn't installed, the
name space will not be available

Suggests: this would seem to be the ticket, except that this is only
supposed to be used for extra packages loaded in examples, not in
actual package R code. On Linux, R CMD check gives a warning that the
reviewers of my package do not like. I'm aware that I can turn off the
strict checking using an environment variable, but that won't convince
my reviewers :)

Enhances: I'm not sure about this one. From what I can see it is not
meant for optional functionality.

I have a dirty trick to silence the warnings, basically instead of
calling package:::function(...), I call
eval(parse(text="package:::function(...)")), but I'd rather do things
transparently. Any way to declare optional extensions?

Thanks,

Peter



More information about the R-help mailing list