library(dm)
## 
## Attaching package: 'dm'
## The following object is masked from 'package:stats':
## 
##     filter
dm <-
  dm_nycflights13() %>%
  dm_add_pk(weather, c(origin, time_hour)) %>%
  dm_add_fk(flights, c(origin, time_hour), weather)

dm %>%
  dm_draw()
dm %>%
  dm_flatten_to_tbl(flights)
## Renamed columns:
## * year -> flights.year, planes.year, weather.year
## * month -> flights.month, weather.month
## * day -> flights.day, weather.day
## * origin -> flights.origin, weather.origin
## * hour -> flights.hour, weather.hour
## * time_hour -> flights.time_hour, weather.time_hour
## * name -> airlines.name, airports.name
## # A tibble: 11,227 x 48
##    flights.year flights.month flights.day dep_time sched_dep_time dep_delay
##  *        <int>         <int>       <int>    <int>          <int>     <dbl>
##  1         2013             1          10        3           2359         4
##  2         2013             1          10       16           2359        17
##  3         2013             1          10      450            500       -10
##  4         2013             1          10      520            525        -5
##  5         2013             1          10      530            530         0
##  6         2013             1          10      531            540        -9
##  7         2013             1          10      535            540        -5
##  8         2013             1          10      546            600       -14
##  9         2013             1          10      549            600       -11
## 10         2013             1          10      550            600       -10
## # … with 11,217 more rows, and 42 more variables: arr_time <int>,
## #   sched_arr_time <int>, arr_delay <dbl>, carrier <chr>, flight <int>,
## #   tailnum <chr>, flights.origin <chr>, dest <chr>, air_time <dbl>,
## #   distance <dbl>, flights.hour <dbl>, minute <dbl>, flights.time_hour <dttm>,
## #   airlines.name <chr>, airports.name <chr>, lat <dbl>, lon <dbl>, alt <dbl>,
## #   tz <dbl>, dst <chr>, tzone <chr>, planes.year <int>, type <chr>,
## #   manufacturer <chr>, model <chr>, engines <int>, seats <int>, speed <int>,
## #   engine <chr>, weather.year <int>, weather.month <int>, weather.day <int>,
## #   weather.hour <int>, temp <dbl>, dewp <dbl>, humid <dbl>, wind_dir <dbl>,
## #   wind_speed <dbl>, wind_gust <dbl>, precip <dbl>, pressure <dbl>,
## #   visib <dbl>