Most vignettes are built when a package is built, but there are occasions where you just want to include a pdf. For example when you want to include a paper. Of course there is a package supporting this, but in this post I will show you how to do it yourself with ease.
The idea is very simple: vignettes can be in LaTeX, and it is possible to include pdf documents in LaTeX using the pdfpages
package. So here's the step-by-step recipe:
- If you do not already have it, create the
vignettes
folder in your package directory. - Put your static pdf there. Let's call it
mypaper.pdf
for now. - Create a
.Rnw
file with the following content.
\documentclass{article}
\usepackage{pdfpages}
%\VignetteIndexEntry{author2019mypaper}
\begin{document}
\includepdf[pages=-, fitpaper=true]{mypaper.pdf}
\end{document}
That's it.
Some notes.
- This repo contains an example.
- The option
fitpaper=true
is necessary because theSweave
package that is included when the vignette is built somehow causes the pages to rescale if it is not included. - If you post your package to CRAN,
myfile.pdf
will be deleted from the directory so it is not part of a binary download. - You can include errata or other notes, for example as follows:
\documentclass{article}
\usepackage{pdfpages}
%\VignetteIndexEntry{author2019mypaper}
\begin{document}
\includepdf[pages=-, fitpaper=true]{mypaper.pdf}
\newpage{}
\subsection*{Errata}
A few things were borked in the original publication, here
is a list of sto0pid things I did:
\begin{itemize}
\item{fubar 1}
\item{fubar 2}
\end{itemize}
\end{document}
Thanks - clear and simple!
I can't seem to get it to work on Windows 10. It complains about pdfltatex can't use Sweave to handle concepts.Rnw etc.
Is this just for Linux and Mac?
No, it works on any OS. The packages where I use this (e.g. validate, stringdist) are also built on Windows by CRAN, including building vignettes.