dm_filter | R Documentation |
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 dplyr::filter()
.
The filters work across related tables:
The resulting dm
object only contains rows that are related
(directly or indirectly) to rows that remain after applying the filters
on all tables.
dm_filter(.dm, ...)
.dm |
A |
... |
Named logical predicates.
The names correspond to tables in the Multiple conditions are combined with |
As of dm 1.0.0, these conditions are no longer stored in the dm
object,
instead they are applied to all tables during the call to dm_filter()
.
Calling dm_apply_filters()
or dm_apply_filters_to_tbl()
is no longer necessary.
Use dm_zoom_to()
and dplyr::filter()
to filter rows without affecting related tables.
An updated dm
object with filters executed across all tables.
dm_nyc <- dm_nycflights13()
dm_nyc %>%
dm_nrow()
dm_nyc_filtered <-
dm_nycflights13() %>%
dm_filter(airports = (name == "John F Kennedy Intl"))
dm_nyc_filtered %>%
dm_nrow()
# 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()
# note that in this example, the only affected table is
# `airports` because the departure airports in `flights` are
# only the three New York airports.
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.