Winter 2020
Preliminaries
- Before developing a R package, I recommend additional knowledge of
- Reference book: R packages by Hadley Wickham and Jenny Bryan
- read for details as I can only cover working knowledge
- vs Writing R Extensions
- the later is official but more difficult to read
package.skeleton()
is also less developer friendly than R studio project
- I will assume we have some R functions ready for bundling into a package
Workflows
- Name our package (nicely)
- avoid name collision, e.g.,
available::available(“rpkg”, browse=F)
- Create directory via File > New Project… > New Directory > R package
- Edit the DESCRIPTION file
- Put the ready R scripts in R/
- document these scripts with roxygen2, e.g., title, description, @param, @examples, @return
- put examples in separate files if they are long and use @example
- (optional) document the package as a whole
- Prepare unit tests, e.g.,
usethis::use_testthat()
- Check the package, e.g.,
devtools::check()
- Write vignettes when our package is relatively stable
Q&A
- How to build a pdf with all available functions’ help manual?
- Use
devtools::build_manual()
.