column-pack {ruler}R Documentation

Column rule pack

Description

Column rule pack is a rule pack which defines a set of rules for columns as a whole, i.e. functions which convert columns of interest to logical values. It should return a data frame with the following properties:

Details

This format is inspired by dplyr's scoped variants of summarise() applied to non-grouped data.

The most common way to define column pack is by creating a functional sequence with no grouping and ending with one of:

Note that (as of dplyr version 0.7.4) when only one column is summarised, names of the output don't have a necessary structure. The 'check column name' is missing which results (after exposure) into empty string in var column of validation report. The current way of dealing with this is to name the input column (see examples).

Using rules()

Using rules() to create list of functions for scoped dplyr "mutating" verbs (such as summarise_all() and transmute_all()) is recommended because:

See Also

Data pack, group pack, row pack, cell pack.

Examples

# Validating present columns
numeric_column_rules <- . %>% dplyr::summarise_if(
  is.numeric,
  rules(mean(.) > 5, sd(.) < 10)
)
character_column_rules <- . %>% dplyr::summarise_if(
  is.character,
  rules(. %in% letters[1:4])
)

col_packs(
  num_col = numeric_column_rules,
  chr_col = character_column_rules
)

# Dealing with one column edge case
improper_pack <- . %>% dplyr::summarise_at(
  dplyr::vars(vs),
  rules(improper_is_chr = is.character)
)

proper_pack <- . %>% dplyr::summarise_at(
  dplyr::vars(vs = vs),
  rules(proper_is_chr = is.character)
)

mtcars %>%
  expose(col_packs(improper_pack, proper_pack)) %>%
  get_report()

[Package ruler version 0.3.0 Index]