This is a simple package illustrating how to incorporate Plumber APIs into an R package. There are two main motivations behind this example:
- Demonstrate how to build Plumber APIs into a package
- Demonstrate how to test Plumber APIs using testthat
# install.packages("remotes")
remotes::install_github("sol-eng/plumbpkg")
The design of this package is heavily influenced by this discussion on RStudio Community.
── DESCRIPTION
├── LICENSE
├── LICENSE.md
├── NAMESPACE
├── R
│ ├── api1.R
│ └── api2.R
├── README.md
├── inst
│ └── plumber
│ ├── api1
│ │ └── plumber.R
│ └── api2
│ ├── entrypoint.R
│ └── plumber.R
├── man
├── plumbpkg.Rproj
└── tests
├── testthat
│ ├── test-api1.R
│ ├── test-api2.R
│ └── test-plumber.R
└── testthat.R
The R/
directory contains all of the R functions used in the Plumber APIs.
This enables the functions to be tested using files in the tests/
directory.
The Plumber APIs are defined in files in inst/plumber/
and are also tested
using testthat and httr.
This repository deploys both APIs to RStudio
Connect using
Travis. The deployment is managed by
scripts/deploy-rsc.sh
and uses the RStudio Connect
API. Because this repository uses Travis, the APIs will only be deployed
after tests have successfully completed.
There are certainly other ways this content could be deployed, either using other CI/CD solutions or using RStudio Connect's ability to publish content from a git repository.