Ecosyste.ms: Awesome

An open API service indexing awesome lists of open source software.

Awesome Lists | Featured Topics | Projects

https://github.com/cynkra/dm

Working with relational data models in R
https://github.com/cynkra/dm

data-model data-warehousing datawarehousing dbi dbplyr r relational-databases

Last synced: 4 days ago
JSON representation

Working with relational data models in R

Awesome Lists containing this project

README

        

---
output:
github_document:
html_preview: false
---

```{r setup, include = FALSE}
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(''))
}
vctrs::s3_register("knitr::knit_print", "grViz")

clean_output <- function(x, options) {
index <- x
index <- gsub("─", "-", index)
index <- strsplit(paste(index, collapse = "\n"), "\n---\n")[[1]][[2]]
writeLines(index, "index.md")

x <- fansi::strip_sgr(x)
x
}

options(cli.num_colors = 256)

local({
hook_source <- knitr::knit_hooks$get("document")
knitr::knit_hooks$set(document = clean_output)
})

# For initial rendering, can be removed
usethis::use_build_ignore("index.md")
```

# [dm](https://dm.cynkra.com/)

[![Lifecycle: stable](https://img.shields.io/badge/lifecycle-stable-brightgreen.svg)](https://lifecycle.r-lib.org/articles/stages.html)
[![R build status](https://github.com/cynkra/dm/workflows/rcc/badge.svg)](https://github.com/cynkra/dm/actions)
[![Codecov test coverage](https://codecov.io/gh/cynkra/dm/branch/main/graph/badge.svg)](https://app.codecov.io/gh/cynkra/dm?branch=main)
[![CRAN status](https://www.r-pkg.org/badges/version/dm)](https://CRAN.R-project.org/package=dm)
[![Launch rstudio.cloud](https://img.shields.io/badge/rstudio-cloud-blue.svg)](https://rstudio.cloud/project/523482)

> 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:

- visualization to help you understand relationships between entities represented by the tables
- simpler joins that "know" how tables are related, including a "flatten" operation that automatically follows keys and performs column name disambiguation
- consistency and constraint checks to help you understand (and fix) the limitations of your data

That's just the tip of the iceberg.
See [Getting started](https://dm.cynkra.com/articles/dm.html) to hit the ground running and explore all the features.

## Installation

The latest stable version of the {dm} package can be obtained from [CRAN](https://CRAN.R-project.org/package=dm) with the command

```r
install.packages("dm")
```

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

```r
# 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:

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

## Usage

Create a dm object (see [Getting started](https://dm.cynkra.com/articles/dm.html) for details).

```{r}
library(dm)
dm <- dm_nycflights13(table_description = TRUE)
dm
```

dm is a named list of tables:

```{r}
names(dm)
nrow(dm$airports)
dm$flights %>%
count(origin)
```

Visualize relationships at any time:

```{r draw, screenshot.force = FALSE}
dm %>%
dm_draw()
```

Simple joins:

```{r}
dm %>%
dm_flatten_to_tbl(flights)
```

Check consistency:

```{r}
dm %>%
dm_examine_constraints()
```

Learn more in the [Getting started](https://dm.cynkra.com/articles/dm.html) article.

## Getting help

If you encounter a clear bug, please file an issue with a minimal reproducible example on [GitHub](https://github.com/cynkra/dm/issues).
For questions and other discussion, please use [community.rstudio.com](https://forum.posit.co/).

---

License: MIT © cynkra GmbH.

Funded by:

[![energie360°](man/figures/energie-72.png)](https://www.energie360.ch/de/)


[![cynkra](man/figures/cynkra-72.png)](https://www.cynkra.com/)

---

Please note that the 'dm' project is released with a [Contributor Code of Conduct](https://dm.cynkra.com/CODE_OF_CONDUCT.html).
By contributing to this project, you agree to abide by its terms.