Building your own R Package
2022-06-09
Chapter 1 Workshop Agenda
- Package setup
- Running checks on package
- Version Control
- Package documentation
- Building package
- Adding Test to the package
- Writing vignettes
1.1 Useful resources
- The official CRAN guidelines Writing R Extensions
- Online book by Hadley Wickham R Packages
- devtools package cheatsheet
- Slides for R Package Workshop by Samantha Toet and Angela Li
1.2 Prerequisites
We need to make sure we have the following packages installed:
install.packages(c("devtools", "roxygen2","usethis", "testthat"))
We will use devtools package to create an appropriate package structure and perform frequent development tasks, like building, installing, and loading the package, checking and updating its documentation, run examples and tests.
Devtools package contains the following core functions:
create()
document()
check()
build()
test()
R package roxygen2 will help us to add manuals and examples to our package.
Finally the testthat package provides functions that make it easy to describe what you expect the function to do, inclusing catching errors, warnings, and messages.