This assumes you have already constructed a package as suggested in Writing R Packages.

Instructions

  1. Add the following lines to your DESCRIPTION file.

    Suggests: knitr
    VignetteBuilder: knitr
  2. 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.)

  3. Run the command

          devtools::build_vignettes()

    The .pdf file created should be in the folder yourpackage/inst/doc/.

Additional Information

knitR is a powerful package. See its main page for details on all the things you can do with it, especially the chunk options.