I am working on a package where much of the functionality involves interacting with an sqlite database. For testing I have a small version of the database that is contained directly within the package. But when creating the vignettes I have used the full sqlite database so that I can fully illustrate how functions work etc. From Hadley's R Packages book in the vignettes chapter:
Note that since you build vignettes locally, CRAN only receives the html/pdf and the source code. However, CRAN does not re-build the vignette. It only checks that the code is runnable (by running it). This means that any packages used by the vignette must be declared in the DESCRIPTION. But this also means that you can use Rmarkdown (which uses pandoc) even though CRAN doesn’t have pandoc installed.
Does this mean that for my vignette to be accepted by CRAN it would need access to the full sqlite database or does "runnable" by chance mean that the code is somehow clean (doubtful). If the vignette does needs completely buildable (which in this case requires the full sqlite database) to be accepted by CRAN what are some strategies for this type of thing here? I can think of two possibilities:
Run the vignette off the small internal sqlite database but have code that sets that chunk to echo=FALSE, eval=TRUE then have another chunk that the user actually sees where echo=TRUE, eval=FALSE so that the user see the code that accesses the full database (that they would have downloaded locally)?
Wrapped all the function calls in the vignette in something like if(file.exist(sqlite database) then run the function...
Any there any other strategies here or am I misunderstanding how CRAN accepts vignettes?
i would be also interested to see what approaches would work for your question.
just an idea, not sure if this would be a way for you but you could in principle save the data as an .rds file with high compression, include it as internal data in your pkg then load it in the database for the vignettes ? not sure if this is a good way - just an idea...
I think this prior thread is relevant to your question:
Basically, it looks like the "best" option is a hybrid of your two options, where you use an environmental variable to determine whether eval is TRUE or FALSE.
These are great solutions. Curious @gergness - you didn't end up using the opts_chunk$set(eval = nzchar(Sys.getenv("MY_ENV_VARIABLE"))) approach but rather a conditional with file.exists. Any reason why?
Mostly because I'm not very familiar with the environmental variable approach, so possibly everything I wanted could have worked with that method.
I wanted users/developers of the package (and Travis CI) to be able to get the data for the vignettes using only a devtools::install_github() command (but I didn't want to add the package to the suggests field to avoid a note from CRAN, so I didn't want to use require()). By checking for the system files of the data package directly, I avoid notes about missing dependencies, but also can be sure that the code is only run when the data is available.
I'm curious to see if there's a better approach though, let me know what you end up doing.
I think this will work because cran only looks to see if the vignettes will run. The actual .html files are generated locally by me with that variable set in my .Renviron file. When cran tries to run the vignette it will just skip trying to run all the code because it does not have that variable set.
Is this still a viable option? I just got a package that used this strategy pulled from CRAN (that followed this pattern) with the message:
Vignettes are supposed to be self-contained but for these packages it
seems at least one vignette depends on packages loaded or objects
generated in others.
This can be seen in the clang-Fedora checks, done with a
currently-optional customization of R CMD check (see the NEWS file in
R-devel).
I'm having some issues installing a new version of R-devel to reproduce the error, and thought in the meantime someone here might know the new work-around.
My use case still works (for now) but that might be because the vignette depends on data being downloaded rather than relying packages. Which package got pulled?
EGRET... unfortunately the note from CRAN came right when the shutdown started, so I wasn't able to do anything to stop it. I'll try a few things today. Worst case, I just take down the offending vignette for now and leave it in the pkgdown site.
Not sure whether this is applicable in your situation, but I got around the issue of external data in vignette by downloading a file from network location to a tempfile() at build time.
Obviously works only for small files (tens of kb in my case), but seems to be OK with CRAN.