Checks a rules table mapping a flag name to a condition and returns it as an admiralease_rules object. Nothing about SAFFL, ITTFL, EFFFL or any other flag is hardcoded: the flags are whatever the table says they are.

pop_rules(x)

Arguments

x

A data frame with the columns above, or an existing admiralease_rules object (returned unchanged).

Value

An admiralease_rules object: a tibble::tibble with FLAG, CONDITION, LABEL and a print() method.

Required columns

FLAG

Name of the variable to create, e.g. "SAFFL".

CONDITION

An R expression, as text, evaluated against the data and returning a logical vector, e.g. "!is.na(TRTSDT)".

LABEL

Optional. Attached to the created column as its label attribute, which xportr writes to the transport file.

Rules are applied top to bottom and each flag is visible to the rules below it, so "SAFFL == \"Y\" & !is.na(BASEEFF)" is a legal condition once SAFFL has been defined earlier in the table.

Examples

rules <- utils::read.csv(
  system.file("extdata", "pop_rules.csv", package = "admiralease")
)
pop_rules(rules)
#> 
#> ── Population flag rules ──
#> 
#>  5 flags, applied in order.
#>  RANDFL = `!is.na(RANDDT)`
#>  SAFFL = `!is.na(TRTSDT)`
#>  ITTFL = `RANDFL == "Y" & TRT01P != "Screen Failure"`
#>  EFFFL = `SAFFL == "Y" & !is.na(BASEEFF)`
#>  COMPLFL = `EOSSTT == "COMPLETED"`