Building R packages
I’m finding an increasing need to be more disciplined and consistent in documentation of analysis procedures in NetLogger. One approach I’m trying is documenting everything in R files. The right way to do this, imho is to use the R package mechanism. So I’m going to use this page to make some basic notes on how to do R packages.
Step 1. Use package.skeleton() to create a basic package layout. Put any initial functions into the package at this time. For example, to create a package called “bestman” in a directory under the NetLogger /trunk, adding one function called foo():
pkg <- "bestman"
pkg.path <- "~/src/nl/trunk/analysis/R-packages"
package.skeleton(name = pkg, c("foo"), path = pkg.path)
Step 2. Add functions to the package with dput() and prompt(). For example, to add a function test() to the package above:
# add documentation file
setwd( paste(pkg.path, pkg, "man", sep = "/") )
prompt(test)
# add source code file
setwd( paste(pkg.path, pkg, "R", sep = "/") )
dput(test, "test.R")
