Skip to main content
Beta
This lesson is in the beta phase, which means that it is ready for teaching by instructors outside of the original author team.
R Packaging
An R package is a project in a standardized folder structure.
An R package centers around R functions.
RStudio is a useful editor that helps you package your project.
To use a package you have to install it
There are several ways of installing a package
To use a homemade package, you also have to build it
The build, install and attach process is usually automated by
RStudio
Functions used inside your package are best referred to with their
full name: <package>::<function>()
“A package is no more and no less than a folder structure”
“RStudio can help you”
“It is important to think about what we want our
package to do (design ) and how to do it
(implementation ). We also want to know why we
need a new package (avoid reinventing the wheel )”
“Functions have to be saved in .R
files in the R
folder”
A license is essential to allow the use and reuse of your
package.
The copyright holder(s) decide(s) on the license.
It is easy to add an open source license to a new R package.
Tests help you write a reliable package
A failing test provides a lot of valuable information
Checking goes deeper than testing
The DESCRIPTION
file helps us keeping track of our
package’s dependencies
Documentation is not optional
All coding projects need a readme file
roxygen2 helps us with the otherwise tedious process of
documenting
roxygen2 also takes care of NAMESPACE
R packages can also include data
Show how to use your functions in a vignette
With RMarkdown, we can combine text, code, and output to a single
document
Vignettes are an integral part of an R package.