Build and deploy data products in R using the framework of Data-as-a-Product (DaaP)
What is a data product?
A data product is a versioned dataset that travels with everything needed to reproduce it: the input data, the logic that derived it, the package dependencies, and the metadata describing where it all came from. In daapr, all of that is captured as code and tracked in git, so a data product can be rebuilt from its configuration alone rather than passed around as a loose file.
daapr was developed for clinical data science, where data is updated frequently and teams struggle to locate the current data, keep track of which inputs and wrangling code produced each file, and govern who can access and change it. While it grew out of that setting, it fits any use case that needs reproducible, versioned data.
A built data product is an R object containing README, input, output, and metadata, annotated with the project and branch it was built from.
Data products are deployed to a board — a governed data space that daapr supports on three backends using the pins package:
- s3, optionally under a prefix within the bucket
- local folders, including mounted drives
- LabKey
Once deployed, consumers retrieve a data product by name and version with the same handful of functions no matter which backend it lives on.
Installation
For released version
remotes::install_github(repo = "daapr-team/daapr")For dev version
remotes::install_github(repo = "daapr-team/daapr", ref = "dev")Quick start
Build and deploy a small data product from the cars dataset. See the getting started guide for a more thorough description of each step.
library(daapr)
# Describe where the data product will live and how to authenticate. These are
# recorded as "dried" calls in the config and hydrated when they are needed, so
# no credentials are ever written to disk.
board_params_set_dried <- fn_dry(board_params_set_s3(
bucket_name = "my-bucket",
prefix = "data-products/", # optional; must end in a trailing slash
region = "us-east-1"
))
creds_set_dried <- fn_dry(creds_set_aws(
key = Sys.getenv("AWS_ACCESS_KEY_ID"),
secret = Sys.getenv("AWS_SECRET_ACCESS_KEY")
))
# 1. Initialize: folder structure, git, renv, and daap_config.yaml
dp_repo <- dp_init(
project_path = "dp_cars",
project_description = "Cars data product",
branch_name = "us001",
branch_description = "User story 1",
readme_general_note = "Data product to explore cars stopping distance",
board_params_set_dried = board_params_set_dried,
creds_set_dried = creds_set_dried,
github_repo_url = "https://github.com/<org>/dp_cars.git"
)
setwd(dp_repo)
config <- dpconf_get(project_path = ".")
# 2. Sync input data to the board and record what was synced
write.csv(cars, "./input_files/cars.csv", row.names = FALSE)
input_map <- dpinput_map(project_path = ".") |> inputmap_clean()
synced_map <- dpinput_sync(conf = config, input_map = input_map)
dpinput_write(project_path = ".", input_d = synced_map)
# 3. Build the data product
data_files_read <- dpinput_read()
output <- data_files_read$cars(config = config) |>
dplyr::mutate(dist_m = 0.3048 * dist)
data_object <- dp_structure(
data_files_read = data_files_read,
output = output,
config = config
)
dp_write(data_object = data_object, project_path = ".")
# 4. Commit, push, and deploy
dp_commit(project_path = ".", commit_description = "First dp build")
dp_push(project_path = ".")
dp_deploy()Using a data product
Consuming a data product needs only the board parameters and credentials — not the project that built it.
board_object <- dp_connect(board_params = board_params, creds = creds)
# What is on this board?
dp_list(board_object = board_object)
# Retrieve one, optionally pinned to a specific version
dp <- dp_get(board_object = board_object, data_name = "dp-cars-us001")Getting started
- New project workflow — what each step of the lifecycle does
- A minimalist example — end to end against an s3 board
- A minimalist example deployed locally — the same, with no cloud account needed
- Read a data product — connecting to s3, local, and LabKey boards as a consumer
- Update input data and update build logic — the two ways a data product changes over time
- FAQ
Project history and older versions
daapr was originally developed at amashadihossein/daapr, alongside the separate dpi, dpbuild, and dpdeploy packages. Active development has moved to this repository — and all future releases will be published here.
As of 1.0.0, those three packages have been merged into daapr itself. library(daapr) is now all that is needed, and code calling dpi::, dpbuild::, or dpdeploy:: should call daapr:: instead. See NEWS for the full set of breaking changes, including the removal of qs support.
The original repositories remain available for anyone who needs an older package version, but they are no longer maintained:
Older versions can be installed from there by pinning a tag, for example:
remotes::install_github(repo = "amashadihossein/daapr@v0.2.0")