Learn R Programming

ruler (version 0.3.0)

act_after_exposure: Act after exposure

Description

A wrapper for consistent application of some actions based on the data after exposure.

Usage

act_after_exposure(.tbl, .trigger, .actor)

Arguments

.tbl

Result of exposure, i.e. data frame with exposure attribute.

.trigger

Function which takes .tbl as argument and returns TRUE if some action needs to be performed.

.actor

Function which takes .tbl as argument and performs the action.

Details

Basically act_after_exposure() is doing the following:

  • Check that .tbl has a proper exposure attribute.

  • Compute whether to perform intended action by computing .trigger(.tbl).

  • If trigger results in TRUE then .actor(.tbl) is returned. In other case .tbl is returned.

It is a good idea that .actor should be doing one of two things:

  • Making side effects. For example throwing an error (if condition in .trigger is met), printing some information and so on. In this case it should return .tbl to be used properly inside a pipe.

  • Changing .tbl based on exposure information. In this case it should return the imputed version of .tbl.

See Also

any_breaker for trigger which returns TRUE in case any rule breaker is found in exposure.

assert_any_breaker for usage of act_after_exposure() in building data validation pipelines.

Examples

Run this code
exposure_printer <- function(.tbl) {
  print(get_exposure(.tbl))
  .tbl
}
mtcars_exposed <- mtcars %>%
  expose(data_packs(. %>% dplyr::summarise(nrow_low = nrow(.) > 50))) %>%
  act_after_exposure(any_breaker, exposure_printer)

Run the code above in your browser using DataLab