From the Writing R Extensions Manual, I read that
As from R 2.14.0 the preferred location for the Sweave sources is the subdirectory vignettes of the source packages, but for compatibility with earlier versions of R, vignette sources will be looked for in inst/doc if vignettes does not exist.
However, when I create a vignettes
subdirectory of the package source, when I run devtools::check()
or R CMD check
I get a warning for Package vignette(s) without corresponding PDF
. If I put the vignette (.Rnw and .pdf) in inst/doc
the check completes without complaints. I tried looking in my library at installed packaged and did not see any directories named vignettes
. Should I still use the deprecated location?
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.
To manually submit your package to CRAN, you create a package bundle (with devtools::build() ) then upload it to https://cran.r-project.org/submit.html, along with some comments which describe the process you followed.
To see the vignette for a specific package, use the argument, browseVignettes("packagename") . Each vignette provides three things: the original source file, a readable HTML page or PDF, and a file of R code. You can read a specific vignette with vignette(x) , and see its code with edit(vignette(x)) .
Function browseVignettes returns an object of the same class; the print method displays it as an HTML page in a browser (using browseURL ).
You put the .Rnw
sources in vignettes/
as you did, but you missed out a critical step; don't check the source tree. The expected workflow is to build the source tarball and then check that tarball. Building the tarball will create the vignette PDF.
R CMD build ../foo/pkg R CMD check ./pkg-0.4.tar.gz
for example will build a source package tarball from the sources in ../foo/pkg
creating the .tar.gz
package in the current directory with the package name and version appended. Then you run R CMD check
on that source package.
If you want your vignette built for you put it in vignettes/
and build the source package. At some future date, R Core may remove the ability to build vignettes from inst/doc
so go with the advised location now and avoid check the sources directly.
I had a hard time interpreting this too.
I believe the intention is that you should put the .Rnw
file in vignettes/
and the PDF (suitably compacted) in inst/doc/
, which technically agrees with the documentation if you read carefully enough. (That is, it says the sources should go in vignettes/
. I don't see where it says in so many words that you ought to put the corresponding PDF in inst/doc/
, but it doesn't not say it, and that interpretation seems to make R CMD check
happy ...)
The resolution is in @GavinSimpson's answer (i.e. one is expected to build the tarball and then check it, rather than checking the source directory itself). (My two cents is that it might be best if R-core officially deprecated (and eventually removed) direct source checking rather than confusing all of us groundlings ...)
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With