I'm developing an R package which handles I/O between a commandline program and an R session. The commandline software requires the user to manually install the software, so installing the package will not ensure the software exists. I would like for the package to eventually be available on CRAN or Bioconductor, so I'm struggling to figure out the best practices for writing vignettes and examples without causing errors. For example, I know that when writing vignettes, even though vignettes are not rebuilt, the code has to run. If the check server is missing the software dependency which will cause my functions to error, will this fail checks? Do I need to wrap each of these code chunks with purl = FALSE
? How do other packages with system-level dependencies handle this issue?
I think you probably need to prevent code from the vignettes, tests and examples to be run. Now, as to how to do that there are several solutions (that I know of).
Note I have no idea how Bioconductor handles missing system requirements, whereas for CRAN it's probably easier to escape code (on CI and R-hub your config/DESCRIPTION should help install the program).
I'm curious to see what others answer, and I guess you already know part of the things I'm writing.
Knowing whether the software is installed
It makes sense to define a function that'd return TRUE
or FALSE
depending on whether the commandline program could be found/started. Then it could be used to skip stuff when checking the package, but also in your functions wrapping the program, to give an informative error message to the user telling them to first install the program.
Vignettes
- You could pre-compute vignettes following the approach described by Jeroen Ooms in an rOpenSci tech note.
- You could indeed use
purl
&eval
. See @jimhester's comment about global knitr options, and this GitHub thread. A chunk could be line the one fromgooglesheet
```{r, echo = FALSE}
NOT_CRAN <- identical(tolower(Sys.getenv("NOT_CRAN")), "true")
knitr::opts_chunk$set(
collapse = TRUE,
comment = "#>",
purl = NOT_CRAN,
eval = NOT_CRAN
)
- You could skip having vignettes and make them "articles" instead, that are present in a
pkgdown
site but not on CRAN/Bioconductor.googledrive
setup. No vignette, no vignette problem.
(I'm working on a blog post about vignettes for the R-hub blog so I like your question!)
Examples
- You could skip them conditionally on the software being installed. I.e. the example code would be
if (cool_tool_is_installed() ) {
cool_package_do()
}
- It'd be less safe/easy to try and skip examples based on donttest/dontrun, since rules change
Tests
- Interesting setup with a custom skipper, described in a
gargle
vignette by @jennybryan. Instead ofdrive_has_token()
you'd usecool_tool_installed()
.
Packages with a similar challenge
- I've mostly given examples of packages whose problem isn't "software available" but "token available" which in a way is similar.
- I'm thinking of the
beastier
package, on CRAN, that has a function for installing a software (to an app dir), and one for checking its installation,is_beast2_installed()
.
This is great, @maelle, and kind of what I was converging on, so it's really nice to see other examples and that there is some consensus on how to handle these issues. The if/else chunks should have occurred to me for my examples, but the precompiling and NOT_CRAN solutions are really clever, and will solve this (and an issue with long-running vignettes!).
Thanks for a thorough response!
This topic was automatically closed 7 days after the last reply. New replies are no longer allowed.