nickr_col: Check that a condition holds on the columns of data between...

Description Usage Arguments Value Examples

Description

Check that a condition holds on the columns of data between pipe stages.

Usage

1
2
nickr_col(.data, cond, msg = "nickr_col", active = TRUE,
  logger = stop)

Arguments

.data

Incoming data (omitted if in pipe).

cond

Column-wise condition expression to test.

msg

User message to display if test fails.

active

Is this check turned on (default TRUE). Set FALSE to disable test (e.g., in production).

logger

Function to call with message (e.g., 'warning' or 'stop').

Value

Input data without modification.

Examples

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
## Not run: 
data %>% mutate(...) %>%

  # Always check that age is greater than or equal to 18.
  nickr_col(age >= 18) %>%

  # Only check that age lies below maximum when not in production.
  nickr_col(age <= max_age, active = !IN.PRODUCTION) %>%

  # Generate a warning if person_id doesn't match the expected pattern.
  nickr_col(str_detect(person_id, "[A-Z][A-Z]"),
            msg = "Person ID must be 2 letters", logger = warning) %>%

  # Further processing on unmodified data.
  filter(...)

## End(Not run)

gvwilson/nickr documentation built on May 9, 2019, 4:05 p.m.