[R-pkg-devel] Avoid reprocessing Rmd vignette

Iñaki Úcar i.ucar86 at gmail.com
Tue Mar 20 11:29:02 CET 2018


2018-03-20 4:04 GMT+01:00 Tim Keitt <tkeitt at utexas.edu>:
> http://www.keittlab.org/
>
> On Mon, Mar 19, 2018 at 6:41 AM, Dirk Eddelbuettel <edd at debian.org> wrote:
>
>>
>> On 18 March 2018 at 21:57, Tim Keitt wrote:
>> | That's a great idea, however my problem is with building a vignette, not
>> | running tests, unless they are linked in some way I'm not understanding.
>>
>> Similar idea applies: condition, just as Inaki and Thierry suggested.  An
>> example for a conditional vignette evaluation is
>>
>> ```{r echo = FALSE, message = FALSE}`r ''`
>> hasData <- requireNamespace("hurricaneexposuredata", quietly = TRUE)
>>           #1
>> if (!hasData) {
>>          #2
>>     knitr::opts_chunk$set(eval = FALSE)
>>          #3
>>     msg <- paste("Note: Examples in this vignette require that the",
>>                  "`hurricaneexposuredata` package be installed. The
>> system",
>>                  "currently running this vignette does not have that
>> package",
>>                  "installed, so code examples will not be evaluated.")
>>     msg <- paste(strwrap(msg), collapse="\n")
>>     message(msg)
>>           #4
>> }
>> ```
>>
>
> That's a great solution. I've used something similar eg
> https://raw.githubusercontent.com/thk686/strider/master/vignettes/strider.Rmd

I see "if (require(pkg))" in that vignette, but not "eval=FALSE".

> I'm still confused however as I was sure that my code chunks were run
> during CRAN check even when the eval option was set to false. But its
> sounding like I made the wrong assumption. Not sure why it did not work
> before.

If "eval=FALSE" is set, code chunks are not run. If you just use "if
(require(pkg))", code chunks *are* run on CRAN, because all packages
are available on CRAN. And, as indicated in "Writing R Extensions",

"Packages used to run examples or tests conditionally (e.g. via
if(require(pkgname))) should be listed in ‘Suggests’ or ‘Enhances’."

That could be the source of the issue maybe?

The idea exposed by Dirk is the same: requireNamespace will find the
package on CRAN and will set eval=TRUE. What you want though is to
avoid running a chunk on CRAN, even if the package is available. So
you need to set eval=FALSE *unconditionally*.

Iñaki

>
> THK
>
>
>>
>> and the paper (https://journal.r-project.org/archive/2017/RJ-2017-026/) by
>> Brooke Anderson and myself discusses #1 to #4.
>>
>> Dirk
>>
>> --
>> http://dirk.eddelbuettel.com | @eddelbuettel | edd at debian.org



More information about the R-package-devel mailing list