Skip to content
Prev 46235 / 63458 Next

SweaveParseOptions, quoted commas, and knitr vignettes

Here is my understanding:

Package vignettes are built through tools::buildVignettes, which first
calls tools::pkgVignettes() to list the vignettes. Due to
loadVignetteBuilder(dir, mustwork = FALSE) in pkgVignettes(), the
vignette engine falls back to utils::Sweave if the specified vignette
builder was not found (in your case, knitr). Then because Sweave
cannot process knitr's Rnw files, the real problem goes under the
disguise of SweaveParseOptions(), which actually came from mustwork =
FALSE.

I think we discussed this issue (offline) before the non-Sweave engine
was introduced in R 3.0.0: if knitr is only required for package
vignettes, should it be specified in Depends/Imports or Suggests? The
former will make sure the vignettes always work because knitr will
always be installed, but if the user installs a prebuilt binary
package from, say, CRAN, he/she does not really need knitr to be
installed, as R will not rebuild the vignettes when installing the
binary packages. Later we decided to go with Suggests only, so that at
least R CMD check will work.

Two approaches to solve the problem:

1. either you Depends on knitr,
2. or make install.packages() also install VignetteBuilder (specified
in DESCRIPTION) when the user chooses to install from source, i.e.
install.packages(..., type = 'source')

I guess 1 is not a good choice.

Or if you want a less cryptic error message, put a code chunk like
this in your Rnw document:

<<setup, include=FALSE>>=
library(knitr)
@

I think R will emit an error that knitr was not installed, which can
be more helpful for the users to realize the real problem.

Regards,
Yihui
--
Yihui Xie <xieyihui at gmail.com>
Phone: 206-667-4385 Web: http://yihui.name
Fred Hutchinson Cancer Research Center, Seattle
On Tue, Jul 16, 2013 at 7:34 PM, Ben Bolker <bbolker at gmail.com> wrote: