Build a vignette for an R package only 1 time

373 Views Asked by At

I am developing a package on 2 separate computers in a repo path that are not identical. When I call devtools::document() and pkgdown::build_site(), I noticed that the entire vignette is re-rendered. The problem is that depending on the machine, the re-rendering results in errors because the paths differ in the 2 machines for the function calls. Is there a way to make vignettes "static" so that they are never re-rendered so that when I pull on another machine and start working on the package that it will inherit the vignette and not-rebuild it?

1

There are 1 best solutions below

1
On

Yes there is -- I do it in a few packages, and there can be many reasons (local differences you describe, wanting to save time, ensuring identical outcomes, ...)

In essence it consists of two steps, and I am describing a pdf vignette here as that is the case I cared about.

First, you render your vignette 'as usual' locally and store it in the package. A subdirectory of vignettes/ will do nicely. The file is now static and will not changed because R will only work in the level of the top-level directory vignettes/.

Second, you add an old-school Sweave vignette of a few lines that includes your premade pdf vignette as input. This was first described by Mark in this blog post. Also make sure your DESCRIPTION file is setup for a standard Sweave vignette. With this setup, you no longer need to declare knitr or RMarkdown because your standard R CMD ... process no longer involves them.

You can look at my anytime package and its vignettes/ directory as a working example.