Skip to contents

Flatten a data model

Usage

flatten_linked_tables(dm, .join = dplyr::left_join)

Arguments

dm

A dm object.

.join

The type of join to be performed, see dplyr::join().

Value

A single table that results from consecutively joining all linked tables.

Examples

library(dm)
#> 
#> Attaching package: ‘dm’
#> The following object is masked from ‘package:stats’:
#> 
#>     filter

dm <- adm_demo()
dm %>% flatten_linked_tables()
#> Warning: Unlinked tables: e
#> Joining with `by = join_by(b_id)`
#> Joining with `by = join_by(c_id)`
#> Joining with `by = join_by(a_id)`
#> Joining with `by = join_by(b_id)`
#> Joining with `by = join_by(d_id)`
#> # A tibble: 1 × 10
#>    a_id     a a_b_id  b_id     b b_c_id  c_id     c  d_id     d
#>   <dbl> <dbl>  <dbl> <dbl> <dbl>  <dbl> <dbl> <dbl> <dbl> <dbl>
#> 1     1     1      1     1     1      1     1     1     1     1

dm %>%
  dm_select_tbl(a, b, a_b) %>%
  flatten_linked_tables()
#> Joining with `by = join_by(a_id)`
#> Joining with `by = join_by(b_id)`
#> # A tibble: 1 × 5
#>    a_id     a  b_id     b a_b_id
#>   <dbl> <dbl> <dbl> <dbl>  <dbl>
#> 1     1     1     1     1      1