For a knitr vignette that you can compile using knit() or with the "Compile PDF" button in RStudio, but that gets an
Error: object 'opts_chunk' not found Execution halted
error when checking or building the package, the package check code is not recognizing that your .Rnw file should be knit
ed and not Sweave
ed. Check that you have the following:
The vignettes are in the vignette directory, if you have R 3.0.0 or higher (this was the solution to this post), cran.r-project.org/doc/manuals/r-devel/R-exts.html#Non_002dSweave-vignettes
Include
%\VignetteEngine{knitr::knitr}
in the vignette metadata, yihui.name/knitr/demo/vignette/Specify
VignetteBuilder: knitr
in the package DESCRIPTION file, andAdd
Suggests: knitr
in DESCRIPTION if knitr is needed only for vignettes
If that does not work add a require(knitr) statement before you set your global options in opts_chunk()
, as Ben Bolker, Yuhui and Tyler Rinker suggested.
If in RStudio: In BOTH the Build configuration and Tool options, set the Sweave option to knitr, www.rstudio.com/ide/docs/authoring/rnw_weave