A brief tour of R
package structure


## Loading required package: methods

R Packages

Package Organization

Core requirements:

  • DESCRIPTION: package metadata

  • R/: home of your R code (.R files)

  • man/: documentation

  • NAMESPACE: specifies what objects are exposed


Other helpful stuff:

  • vignettes/: long-form documentation

  • tests/: home of your unit tests

  • data/: home of sample datasets

  • inst/: anything else that should come along for the ride

  • src/: compiled source code (e.g. C, C++ and/or Fortran)

Initializing a package

The old way:

  • Base R implementation package.skeleton()

The new way:

  • Eddelbuettel’s pkgKitten

    • kitten() as a drop in replacement for package.skeleton()


  • Hadley’s devtools

    • create() setups the basics, lots of other add ons and tie-ins.

Building and checking a package

The old way (via the shell):

  • R CMD build pkg - construct a zipped file containing the package, source packages by default, but can compile and link source file if needed.

  • R CMD check pkg - runs the extensive tests required by CRAN.


The new way (via devtools):

  • build() / check() - same stuff but inside of the R session.

HW4 as a package

Acknowledgments

Acknowledgments

Above materials are derived in part from the following sources: