Precompiling vignette with devtools


#1

I’m working on a package that allows importing the IPUMS data into R and I want to include vignettes that are based on our tutorials for other statistical packages. The one issue is that these tutorials use datasets that are too large to fit on CRAN.

It seems like it is possible to submit pre-compiled vignettes to CRAN (here’s how to do with R.rsp). This way I can have the data in a separate github package, but won’t have to include the github package in the Suggests field. This avoids a R CMD Check note about a non-CRAN package dependency, which wouldn’t really be the end of the world, but I’d still like to avoid.

Since I’ve only used devtools to build my vignettes in the past, I’m blissfully ignorant of the finer details of how the vignette gets made. Is this kind of approach possible with knitr and devtools?


Vignettes that require locally stored data
#2

This article is very relevant to your problem:

Hosting Data Packages via drat: A Case Study with Hurricane Exposure Data
G. Brooke Anderson and Dirk Eddelbuettel , The R Journal (2017) 9:1, pages 486-497.

https://journal.r-project.org/archive/2017/RJ-2017-026/index.html

The bit especially relevant to you is setting chunk option eval = FALSE for any vignette chunks that CRAN should not re-run. That is somewhat separate from whether you make the data package available only on GitHub or via an alternative repository (drat is described in the article).


#3

That fixes the R CMD Check warnings, but if I set eval = FALSE, then I don’t get output at all, right? Is there a way to eval on my machine so that the vignette’s output is filled in, but not CRAN?


#4

Oh, googlesheets looks like it does this (because you don’t want CRAN to have your gmail credentials). I’ll see if I can mimic that.


#5

Right, you have to conditionally set eval = FALSE. CRAN does use the vignettes you build, but their checks will still attempt to run the code up to 3 times, I think.

Yes, googlesheets has similar problems, but worse because of the need to exclude the token file. Although I now think my solution there is overly complex, which is why I didn’t point directly to it.


#6

Probably the lightest weight way to do this is to set a global knitr option in the setup chunk of the vignette which is true if a environment variable is set and FALSE otherwise. Then you can set the environment variable in your local .Renviron file (and potentially on CI services like travis). This way the vignette chunks will be run when you build your package locally but not when CRAN builds and checks your package.

opts_chunk$set(eval = nzchar(Sys.getenv("MY_ENV_VARIABLE")))