Learn R Programming

ruler (version 0.1.3)

rules: Create a list of rules

Description

rules() is a wrapper for dplyr's funs which provides a different naming scheme.

Usage

rules(..., .args = list(), .prefix = "._.")

Arguments

...

A list of functions (as in funs).

.args

A named list of additional arguments to be added to all function calls (as in funs).

.prefix

Prefix to be added to function names.

Details

rules() behaves exactly as funs() with only difference being the names of the output. The following naming scheme is applied:

  • Absent names are replaced with the 'rule..{ind}' where {ind} is the index of function position in the ... .

  • .prefix is added at the beginning of all names. The default is ._. . It is picked for its symbolism (it is the Morse code of letter 'R') and rare occurrence in names. In those rare cases it can be manually changed but this will not be tracked further.

Examples

Run this code
# NOT RUN {
rules_1 <- rules(mean, sd, .args = list(na.rm = TRUE))
rules_1_ref <- dplyr::funs('._.rule..1' = mean, '._.rule..2' = sd,
                           .args = list(na.rm = TRUE))
identical(rules_1, rules_1_ref)

rules_2 <- rules(mean, sd = sd, "var")
rules_2_ref <- dplyr::funs(
  '._.rule..1' = mean,
  '._.sd' = sd,
  '._.rule..3' = "var"
)
identical(rules_2, rules_2_ref)

rules_3 <- rules(mean, .prefix = "__")
rules_3_ref <- dplyr::funs('__rule..1' = mean)
identical(rules_3, rules_3_ref)

# }

Run the code above in your browser using DataLab