Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

Tags:

r

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?

like image 229
Pierre Avatar asked Mar 28 '12 01:03

Pierre


People also ask

What is a package vignette?

A vignette is like a book chapter or an academic paper: it can describe the problem that your package is designed to solve, and then show the reader how to solve it. Many existing packages have vignettes. You can see all the installed vignettes with browseVignettes() .

How do I add a vignette to a package in R?

To create a package vignette in R Markdown, the easiest way is through the RStudio menu File -> New File -> R Markdown -> From Template (see Figure 16.4). Then you select “Package Vignette” from the rmarkdown package, and you will get a vignette template.

How the packages are imported in R language?

Alternatively, you can install R packages from the menu. In RStudio go to Tools → Install Packages and in the Install from option select Repository (CRAN) and then specify the packages you want. In classic R IDE go to Packages → Install package(s) , select a mirror and install the package.

What is browseVignettes?

Function browseVignettes returns an object of the same class; the print method displays it as an HTML page in a browser (using browseURL ).


2 Answers

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.

like image 191
Ben Bolker Avatar answered Nov 02 '22 04:11

Ben Bolker


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).

like image 36
cbeleites unhappy with SX Avatar answered Nov 02 '22 04:11

cbeleites unhappy with SX