library(tidyverse)
library(dm)

knitr::opts_chunk$set(
  collapse = TRUE,
  comment = "#>",
  fig.path = "man/figures/README-",
  out.width = "100%"
)

knit_print.grViz <- function(x, ..., options) {
  svg <- DiagrammeRsvg::export_svg(x)
  svg <- sub('[<]polygon fill="#ffffff"[^/]+/[>]\n', "", svg)
  path <- paste0(options$fig.path, options$label, ".svg")
  writeLines(svg, path)

  knitr::asis_output(paste0('<img src="', path, '" />'))
}
vctrs::s3_register("knitr::knit_print", "grViz")

options(cli.num_colors = 256)

dm

Lifecycle: stable R build status Codecov test coverage CRAN status Launch rstudio.cloud

Are you using multiple data frames or database tables in R? Organize them with dm.

  • Use it for data analysis today.
  • Build data models tomorrow.
  • Deploy the data models to your organization's Relational Database Management System (RDBMS) the day after.

Overview

dm bridges the gap in the data pipeline between individual data frames and relational databases. It's a grammar of joined tables that provides a consistent set of verbs for consuming, creating, and deploying relational data models. For individual researchers, it broadens the scope of datasets they can work with and how they work with them. For organizations, it enables teams to quickly and efficiently create and share large, complex datasets.

dm objects encapsulate relational data models constructed from local data frames or lazy tables connected to an RDBMS. dm objects support the full suite of dplyr data manipulation verbs along with additional methods for constructing and verifying relational data models, including key selection, key creation, and rigorous constraint checking. Once a data model is complete, dm provides methods for deploying it to an RDBMS. This allows it to scale from datasets that fit in memory to databases with billions of rows.

Features

dm makes it easy to bring an existing relational data model into your R session. As the dm object behaves like a named list of tables it requires little change to incorporate it within existing workflows. The dm interface and behavior is modeled after dplyr, so you may already be familiar with many of its verbs. dm also offers:

That's just the tip of the iceberg. See Getting started to hit the ground running and explore all the features.

Installation

The latest stable version of the {dm} package can be obtained from CRAN with the command

install.packages("dm")

The latest development version of {dm} can be installed from R-universe:

# Enable repository from cynkra
options(
  repos = c(
    cynkra = "https://cynkra.r-universe.dev",
    CRAN = "https://cloud.r-project.org"
  )
)
# Download and install dm in R
install.packages('dm')

or from GitHub:

# install.packages("devtools")
devtools::install_github("cynkra/dm")

Usage

Create a dm object (see Getting started for details).

library(dm)
dm <- dm_nycflights13(table_description = TRUE)
dm

dm is a named list of tables:

names(dm)
nrow(dm$airports)
dm$flights %>%
  count(origin)

Visualize relationships at any time:

dm %>%
  dm_draw()

Simple joins:

dm %>%
  dm_flatten_to_tbl(flights)

Check consistency:

dm %>%
  dm_examine_constraints()

Learn more in the Getting started article.

Getting help

If you encounter a clear bug, please file an issue with a minimal reproducible example on GitHub. For questions and other discussion, please use community.rstudio.com.


License: MIT © cynkra GmbH.

Funded by:

energie360° cynkra


Please note that the 'dm' project is released with a Contributor Code of Conduct. By contributing to this project, you agree to abide by its terms.



krlmlr/dm documentation built on April 19, 2024, 5:23 p.m.