dm_from_con()
dm(df1, df2, ...)
dm(dm1, df1...)
dm_add_pk()
, dm_add_fk()
Automatic for MariaDB, SQL Server, Postgres, and others.
Identify potential primary keys:
dm_enum_pk_candidates()
: columns, candidate, why.Identify potential foreign keys:
dm_enum_fk_candidates()
: columns, candidate, why.The dm package provides a grammar of relational data models. It helps maintain referential integrity.
A dm behaves like a list of tables (data frames or lazy tables) capturing relationships between the tables.
Shiny app: dm_gui(dm = dm1)
dm_select_tbl(dm1, ...)
dm_rename_tbl(dm1, ...)
dm_select(dm1, table, ...)
Automatic update of dm meta-information and table relations.
dm_rename(dm1, table, ...)
dm_filter(dm1, table = (pred))
Filter rows in the table where the condition is defined, but also all directly/indirectly connected tables.
dm_draw()
dm_draw(view_type = "keys_only")
.dm_draw(view_type = "all")
.dm_draw(view_type = "title_only")
.To visualize fewer tables first use dm_select_tbl()
.
dm_set_colors()
dm_examine_constraints()
tibble with information about which key constraints are met or violated.
dm_examine_cardinalities()
tibble with information about the cardinality of the foreign keys constraints.
check_key(df, col1)
returns an error if not an unique key.
check_subset(df1, df2)
returns an error if df1
is not a subset of
df2
.
check_set_equality(df1, df2)
returns an error if df1
and df2
are not the
same sets.
dm_disambiguate_cols()
dm_disambiguate_cols(dm1)
ensures that all columns in a
dm have unique names.
dm_flatten_to_tbl()
Only direct neighbours: dm_flatten_to_tbl()
All neighbours: dm_flatten_to_tbl(.recursive = TRUE)
dm_wrap_tbl()
Parent tables are packed — dm_pack_tbl()
.
Child tables are nested — dm_nest_tbl()
.
pull_tbl()
dm_get_tables(keyed = TRUE)
: dm_zoom_to()
: Zoom on a table.mutate()
, etc.).dm_update_zoomed()
(replace) /
dm_insert_zoomed()
copy_dm_to()
Need a database connection —
DBI::dbConnect()
.
Methods:
dm_rows_insert(dm1, dm2)
: adds new rowsdm_rows_update(dm1, dm2)
: changes values in rowsdm_rows_patch(dm1, dm2)
: fills in missing valuesdm_rows_upsert(dm1, dm2)
: adds new or changes rowsdm_rows_delete(dm1, dm2)
: deletes rowsdm1 |>
dm_rows_insert(dm2, in_place = FALSE)
dm1 |>
dm_rows_insert(dm2, in_place = TRUE)
A dm is immutable, except with
in_place = TRUE
.