These notes just describe how to create a package — they won’t describe the whole development workflow of writing code, testing, building, etc.
The usethis package heavily scaffolds creating and modifying components of an R package.
Create the Package
Navigate to the directory we want the package to live in, then run the following R code:
This will create a pretty bare-bones package, including DESCRIPTION
and NAMESPACE
files.
Adding Other Components
{usethis}
contains helper functions to add other components we might want to use in our package. These functions are all prefixed with use_**
, e.g. use_make()
will create a makefile, use_mit_license()
will add an MIT license to the package, etc.
Here’s a reference for these functions, but here are the ones I find most useful:
use_r("file_name")
— creates an R fileuse_test("file_name")
— creates a test file for “file_name”use_readme_rmd()
— creates aREADME.rmd
file. This is my default, but I’ll sometimes useuse_readme_md()
if I don’t need to execute R code when I generate my readme.use_testthat()
— sets up testing via testthatuse_mit_license()
— adds the MIT license to the projectuse_pkgdown
oruse_pkgdown_github_pages()
— creates a pkgdown docs site.use_package("pkg_name")
— depend on another packageuse_dev_package("pkg_name", remote)
— depend on a development packageuse_git()
— initializes a git repository for the package