Filtering a table of a
dm object may affect other tables that are connected to it
directly or indirectly via foreign key relations.
dm_filter() can be used to define filter conditions for tables using syntax that is similar to
The filters work across related tables:
dm object only contains rows that are related
(directly or indirectly) to rows that remain after applying the filters
on all tables.
Named logical predicates. The names correspond to tables in the
dmobject. The predicates are defined in terms of the variables in the corresponding table, they are passed on to
Multiple conditions are combined with
&. Only the rows where the condition evaluates to
As of dm 1.0.0, these conditions are no longer stored in the
instead they are applied to all tables during the call to
dm_apply_filters_to_tbl() is no longer necessary.
dm_nyc <- dm_nycflights13() dm_nyc %>% dm_nrow() #> airlines airports flights planes weather #> 15 86 1761 945 144 dm_nyc_filtered <- dm_nycflights13() %>% dm_filter(airports = (name == "John F Kennedy Intl")) dm_nyc_filtered %>% dm_nrow() #> airlines airports flights planes weather #> 10 1 602 336 38 # If you want to keep only those rows in the parent tables # whose primary key values appear as foreign key values in # `flights`, you can set a `TRUE` filter in `flights`: dm_nyc %>% dm_filter(flights = (1 == 1)) %>% dm_nrow() #> airlines airports flights planes weather #> 15 3 1761 945 105 # note that in this example, the only affected table is # `airports` because the departure airports in `flights` are # only the three New York airports.