This assumes you have already constructed a package as suggested in Writing R Packages.
Add the following lines to your DESCRIPTION file.
Suggests: knitr
VignetteBuilder: knitr
Create a directory vignettes
in your package’s root directory, and put your .Rnw
file in it. Here’s an example vignette file and a BibTeX file you can start with. (This is the vignette it generates.)
Run the command
devtools::build_vignettes()
The .pdf
file created should be in the folder yourpackage/inst/doc/
.
knitR
is a powerful package. See its main page for details on all the things you can do with it, especially the chunk options.