This repository can be used as a boilerplate when creating a new R package. It contains a basic package structure and a few valuable files to get started.
Unique feature included in this template:
- A basic unit testing framework using
testthat
. - A basic documentation framework using
roxygen2
. - Github Actions for CI/CD.
To use this template to create your own R-Package, follow these steps:
- R
devtools
is required when developing R packages. Install and Reboot:
install.packages("devtools")
- Install the unit testing framework
testthat
:
install.packages("testthat")
-
Create new Repository: click the
Use this template
button to create a new repository. -
Clone Repository
git clone <Repo URL>
- Update
README.md
- Update
DESCRIPTION
- Update
tests/testthat.R
: change the reference inlibrary()
andtest_check()
with your package name. - Update documentation using
devtools
in r terminal
devtools::document()
- Check the Package using
devtools
in r terminal
devtools::check()
By design, R packages leverage a specific folder structure. This structure is used by devtools
to document, check and build packages.
Here is an overview of the different files and folders that comprise the package structure.
Files:
DESCRIPTION
: Contains the package metadata. This file defines the package name, version, dependencies and other metadata.NAMESPACE
: Contains the package namespace. This file is used to define the package exports and imports.LICENSE
: Contains the package license. This file is used to define the package license.README.md
: Contains the package readme. This file is used to provide a high-level overview of the package.
Folders:
man
: Contains the documentation files. These files are generated bydevtools
and should not be edited manually.R
: Contains the R source code files. These files define the functions and data structures that make up the package.tests
: Contains the unit tests. These files test the functions and data structures that make up the package.vignettes
: Contains the vignettes. These files are used to provide additional documentation and examples.
Most of your time developing R packages will be spent in the R and Tests folders. Files in man
and vignettes
are generated by devtools
and should not be edited manually. Also, the contents in the NAMESPACE
file should not be edited manually.