What is the proper way, to include a static PDF file as a \"vignette\" in a CRAN package as of R 3.0?
The trick described in this document of using an empty stub
UPDATE 2014-06-08: For a better solution to including static PDFs and HTML files in an R package, see my other answer in this thread on how to use R.rsp (>= 0.19.0) and its R.rsp::asis
vignette engine.
All you need is a
file with a name matching your static
file, e.g.
vignettes/
static.pdf
static.Rnw
where
(here static.Rnw
) is a minimal valid Sweave file, e.g.
%\VignetteIndexEntry{}
\documentclass{article}
\begin{document}
\end{document}
This vignette source file (
) tricks R CMD build
to build it, i.e. R's tools::buildVignettes()
will first Sweave
into
as usual. However, due to how buildVignettes()
is designed it will detect our static
file as already being created by the Sweave engine and therefore it will not compile that dummy TeX file into a PDF file (which would overwrite our static file).
What is important to understand is that (i) vignettes are "build" during R CMD build
, (ii) and when built they are copied over to the inst/doc/
directory (created if missing) of the built package. Also, (iii) the vignettes/
directory will not be part of the build package, i.e.
file. So, make sure to look in inst/doc/
.
So, to be clear here, using a dummy
could be considered a hack that may break if someone decides to prevent against this strategy. However, if that happens, it is fully possible to create a non-Sweave vignette engine which sole purpose is to compile a
file into a ...
file. This is valid and possible due to the non-Sweave support added in R (>= 3.0.0). I've been considering adding such engine to the R.rsp package, e.g. \VignetteEngine{R.rsp::StaticPDF}. With that you would not even have to have that dummy Rnw file - only the PDF file.
Hope this helps