8

I have a number of vignettes in an R package that are slow to run. As I understand it, a CRAN R CMD check will not rebuild the vignette but will run its corresponding code.

Since the vignettes are slow to run, I don't think the adhere to the CRAN policy. But the vignettes are useful examples that have figures. So I was wondering if it's possible to skip running vignette code only for a CRAN R CMD check, a bit like you can skip a unit test using testthat::skip_on_cran()?

Jack
  • 367
  • 2
  • 10
  • 3
    Look at `R CMD check --help`. – Dirk Eddelbuettel Jul 13 '17 at 23:17
  • 1
    Aah okay thanks, I also wondered if there's a way to specify that CRAN uses this option? – Jack Jul 13 '17 at 23:22
  • 1
    You can also run (parts of) the vignettes and install them as pre-built documentation so that they don't run each time. That introduces a threat they stop working correctly and the need for you to rebuild them each time you update the package code, but can get you around this timing issue. – Thomas Jul 14 '17 at 10:15
  • @Jack Did you find a solution to skip running vignette code on CRAN? – miguelmorin May 22 '19 at 20:31
  • I had a work around but you prompted me to get to the bottom of this. I'll write up as a solution. – Jack May 23 '19 at 09:38

2 Answers2

3

Dirk's comment about R CMD check is --helpful. You will see a --no-vignettes flag.

If you're using devtools from the R console, just use:

devtools::check(vignettes = FALSE)

zdebruine
  • 3,687
  • 6
  • 31
  • 50
1

I just found there is an environment variable used by devtools called NOT_CRAN, and we should be able to use the same ideas to check if things are being run as CRAN. I believe wrapping code in the following if statement will mean it is only run if you are not using the --as-cran statement.

if (identical(Sys.getenv("NOT_CRAN", unset = "true"), "true")) {
    ###CODE HERE###
}

I think even if this has been set by devtools it should still work.

Sources: Testing -- R Packages by Hadley Wickham; testthat package source; devtools package source.

Jack
  • 367
  • 2
  • 10
  • The code runs both when I build the vignette and when I call `devtools::check()`, where `cran = TRUE` is the default and checks using the same settings as CRAN. I'll see if it works when I release on CRAN. – miguelmorin May 23 '19 at 21:39