rules {ruler}R Documentation

Create a list of rules

Description

rules() is a function designed to create input for .funs argument of scoped dplyr "mutating" verbs (such as summarise_all() and transmute_all()). It converts bare expressions with . as input into formulas and repairs names of the output.

Usage

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

Arguments

...

Bare expression(s) with . as input.

.prefix

Prefix to be added to function names.

Details

rules() repairs names by the following algorithm:

Examples

# `rules()` accepts bare expression calls with `.` as input, which is not
# possible with advised `list()` approach of `dplyr`
dplyr::summarise_all(mtcars[, 1:2], rules(sd, "sd", sd(.), ~ sd(.)))

dplyr::summarise_all(mtcars[, 1:2], rules(sd, .prefix = "a_a_"))

# Use `...` in `summarise_all()` to supply extra arguments
dplyr::summarise_all(data.frame(x = c(1:2, NA)), rules(sd), na.rm = TRUE)

[Package ruler version 0.3.0 Index]