Add a static pdf vignette to an R package

[This article was first published on R – Mark van der Loo, and kindly contributed to R-bloggers]. (You can report issue about the content on this page here)
Want to share your content on R-bloggers? click here if you have a blog, or here if you don't.

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:

  1. If you do not already have it, create the vignettes folder in your package directory.
  2. Put your static pdf there. Let’s call it mypaper.pdf for now.
  3. 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.

  1. This repo contains an example.
  2. The option fitpaper=true is necessary because the Sweave package that is included when the vignette is built somehow causes the pages to rescale if it is not included.
  3. If you post your package to CRAN, myfile.pdf will be deleted from the directory so it is not part of a binary download.
  4. 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}

To leave a comment for the author, please follow the link and comment on their blog: R – Mark van der Loo.

R-bloggers.com offers daily e-mail updates about R news and tutorials about learning R and many other topics. Click here if you're looking to post or find an R/data-science job.
Want to share your content on R-bloggers? click here if you have a blog, or here if you don't.

Never miss an update!
Subscribe to R-bloggers to receive
e-mails with the latest R posts.
(You will not see this message again.)

Click here to close (This popup will not appear again)