Pierre
Pierre

Reputation: 1045

Is it possible to use non-imported packages in a package vignette?

I'm writing a vignette for one of my packages.

In this vignette, I would like to demonstrate how this package can interact with other packages that are not being imported by the NAMESPACE or by the Imports section of the DESCRIPTION file.

So, I'm putting a require call to use these external packages in my vignette, but of course I got the following NOTE when I try to R CMD check the package:

* checking for unstated dependencies in vignettes ... NOTE
‘library’ or ‘require’ call not declared from: ‘RColorBrewer’

Is there any way around this, or should I either import these external packages or "fake" the vignette using eval=FALSE?

Upvotes: 26

Views: 2630

Answers (2)

Ben Bolker
Ben Bolker

Reputation: 226332

Put it in Suggests: of your DESCRIPTION file.

From p. 6 of the R extensions manual:

The ‘Suggests’ field uses the same syntax as ‘Depends’ and lists packages that are not necessarily needed. This includes packages used only in examples, tests or vignettes (see Section 1.4 [Writing package vignettes], page 26), and packages loaded in the body of functions. E.g., suppose an example from package foo uses a dataset from package bar. Then it is not necessary to have bar use foo unless one wants to execute all the examples/tests/vignettes: it is useful to have bar, but not necessary. Version requirements can be specified, and will be used by R CMD check.

Upvotes: 33

cbeleites
cbeleites

Reputation: 14093

In addition if the vignette properly depends on that package, there should be a

% \VignetteDepends{...}

statement in the vignette itself: Sweave, Part II: Package Vignettes, R News 3/2 (Oct. 2003), 21 - 24.

However, your case possibly is a bit different:

I use if (require ("pkgxy")) without % \\VignetteDepends{pkgxy} (Suggests: pkgxy in the DESCRIPTION is needed anyways) for some things I want to show but where I don't want to force the user to have all the suggested pacakges installed. I put a box at the beginning of the vignette where I report which of those packages are available and if a package is not available when the vignette is built, an "pkgxy is needed to do this" text is put into the vignette.

The "introduction" vignette of package hyperSpec is an example (to find out how it actually works, you need not only the .Rnw but also some more definitions).

Upvotes: 8

Related Questions