Emits code that assigns each table in the dm to a variable,
using pull_tbl()
with keyed = TRUE
.
These tables retain information about primary and foreign keys,
even after data transformations,
and can be converted back to a dm object with dm()
.
Examples
dm <- dm_nycflights13()
dm_deconstruct(dm)
#> airlines <- pull_tbl(dm, "airlines", keyed = TRUE)
#> airports <- pull_tbl(dm, "airports", keyed = TRUE)
#> flights <- pull_tbl(dm, "flights", keyed = TRUE)
#> planes <- pull_tbl(dm, "planes", keyed = TRUE)
#> weather <- pull_tbl(dm, "weather", keyed = TRUE)
airlines <- pull_tbl(dm, "airlines", keyed = TRUE)
airports <- pull_tbl(dm, "airports", keyed = TRUE)
flights <- pull_tbl(dm, "flights", keyed = TRUE)
planes <- pull_tbl(dm, "planes", keyed = TRUE)
weather <- pull_tbl(dm, "weather", keyed = TRUE)
by_origin <-
flights %>%
group_by(origin) %>%
summarize(mean_arr_delay = mean(arr_delay, na.rm = TRUE)) %>%
ungroup()
by_origin
#> # A tibble: 3 × 2
#> # Keys: `origin` | 0 | 0
#> origin mean_arr_delay
#> <chr> <dbl>
#> 1 EWR 3.43
#> 2 JFK -4.36
#> 3 LGA 0.523
dm(airlines, airports, flights, planes, weather, by_origin) %>%
dm_draw()