Create R Package
Readings
Lesson
- Developing R Packages with RStudio
- Building, Testing, and Distributing Packages
- Writing Package Documentation
- Writing documents for R package
R package checklist
- Check out (clone) the package repository as a RStudio project or create a R package project from RStudio menu File/New Project…;
- Test that the pakcage builds and loads without issue;
- Check the package with
devtools::check()
, which also runs tests inlcuded in the package; verify there are no errors or warnings;
- Does the package include tests? Do the tests run successfully?
- Verify that the package includes proper documents as roxygen comments in the R code files;
- (Does the package include vignettes?)
- Install the package and load it with
library
;
- See what functions are provided by the package with
ls("package:<package name>")
after loading it with library
;
- Study the vignettes and help documents to learn how to use it.
Exercise
Re-organize the function(s) you developed in the R coding basics section into a R package:
- Use roxgen comments to specify the dependencies of your function(s);
- Use roxgen comments to document your function(s);
- [Advanced] Create tests for your functions;
- Make sure your package build and load properly;
- Go through the R package checklist;
- Commit your package as a GitHub repository.
Learning more
- R Package by Hadley Wickham
- Making Your First R Package by Fong Chun Chan
- A Quickstart Guide for Building Your First R Package