Free Access Week - Data Engineering + BI
Data Engineering and BI courses are free this week!
Free Access Week - Jun 2-8

dm (version 0.0.3)

cdm_filter: Filtering a dm object

Description

Filtering one table of a dm object has an effect on all tables connected to this table via one or more steps of foreign key relations. Firstly, one or more filter conditions for one or more tables can be defined using cdm_filter(), with a syntax similar to dplyr::filter(). These conditions will be stored in the dm and not immediately executed. With cdm_apply_filters() all tables will be updated according to the filter conditions and the foreign key relations.

Usage

cdm_filter(dm, table, ...)

cdm_apply_filters(dm)

Arguments

dm

A dm object.

table

A table in the dm

...

Logical predicates defined in terms of the variables in .data, passed on to dplyr::filter(). Multiple conditions are combined with & or ,. Only rows where the condition evaluates to TRUE are kept.

The arguments in ... are automatically quoted and evaluated in the context of the data frame. They support unquoting and splicing. See vignette("programming", package = "dplyr") for an introduction to these concepts.

Details

cdm_filter() allows you to set one or more filter conditions for one table of a dm object. These conditions will be stored in the dm for when they are needed. Once executed, the filtering the will affect all tables connected to the filtered one by foreign key constraints, leaving only the rows with the corresponding key values. The filtering implicitly takes place, once a table is requested from the dm by using one of tbl(), [[.dm(), $.dm().

With cdm_apply_filters() all set filter conditions are applied and their combined cascading effect on each table of the dm is taken into account, producing a new dm object. This function is called by the compute() method for dm class objects.

Examples

Run this code
# NOT RUN {
library(dplyr)

dm_nyc_filtered <-
  cdm_nycflights13() %>%
  cdm_filter(airports, name == "John F Kennedy Intl")

tbl(dm_nyc_filtered, "flights")
dm_nyc_filtered[["planes"]]
dm_nyc_filtered$airlines

cdm_nycflights13() %>%
  cdm_filter(airports, name == "John F Kennedy Intl") %>%
  cdm_apply_filters()
cdm_nycflights13() %>%
  cdm_filter(flights, month == 3) %>%
  cdm_apply_filters()

library(dplyr)
cdm_nycflights13() %>%
  cdm_filter(planes, engine %in% c("Reciprocating", "4 Cycle")) %>%
  compute()
# }

Run the code above in your browser using DataLab