![](https://csdnimg.cn/release/download_crawler_static/16820662/bg10.jpg)
Chapter 1: Creating R packages 11
created. Documents in ‘inst/doc’ can be in arbitrary format, however we strongly rec-
ommend to provide them in PDF format, such that users on all platforms can easily read
them.
A special case are documents in Sweave format, which we call package vignettes. Sweave
allows to integrate LaT
E
X documents and R code and is contained in package tools which is
part of the base R distribution, see the Sweave help page for details on the document format.
Package vignettes found in directory ‘inst/doc’ are tested by R CMD check by executing all
R code chunks they contain to ensure consistency between code and documentation. Note
that even code chunks with option eval=FALSE are tested, if you want code in a vignette
that s hould not be tested, move it to a normal LaTeX verbatim environment. The reason
for this policy is that users should be able to rely on code examples to be executable as
seen in the vignette. The R working directory for all vignette tests in R CMD check is the
installed version of the ‘doc’ subdirectory. Make sure all files needed by the vignette (data
sets, . . . ) are accessible by either placing them in the ‘inst/doc’ hierarchy of the source
package, or using calls to system.file().
R CMD build will automatically create PDF versions of the vignettes for distribution
with the package sources. By including the PDF version in the package sources it is not
necessary that the vignettes can be compiled at install time, i.e., the package author c an
use private LaT
E
X extensions which are only available on his machine. Only the R code
inside the vignettes is part of the checking procedure, typesetting manuals is not part of
the package QC.
By default R CMD build will run Sweave on all files in Sweave format. If no ‘Makefile’
is found in directory ‘inst/doc’, then texi2dvi --pdf is run on all vignettes. Whenever
a ‘Makefile’ is found, then R CMD build will try to run make after the Sweave step, such
that PDF manuals can be created from arbitrary source formats (plain LaT
E
X files, . . . ).
The ‘Makefile’ should take care of both creation of PDF files and cleaning up afterwards,
i.e., delete all files that shall not appear in the final package archive. Note that the make
step is executed independently from the presence of any files in Sweave format.
It is no longer necessary to provide a ‘00Index.dcf’ file in the ‘inst/doc’ directory—
the corresponding information is generated automatically from the \VignetteIndexEntry
statements in all Sweave files when installing from source, or when using the package builder
(see Section 1.3 [Checking and building packages], page 9). The \VignetteIndexEntry
statement is best placed in LaT
E
X comment, such that no definition of the command is
necessary.
At install time an HTML index for all vignettes is automatically created from the
\VignetteIndexEntry statements unless a file ‘index.html’ exists in directory ‘inst/doc’.
This index is linked into the HTML help system for each package.
1.5 Submitting a package to cran
cran is a network of WWW sites holding the R distributions and contributed code, espe-
cially R packages. Users of R are encouraged to join in the collaborative project and to
submit their own packages to cran.