funs() provides a flexible way to generate a named list of functions for input to other functions like summarise_at().

funs(..., .args = list())

Arguments

...

A list of functions specified by:

  • Their name, "mean"

  • The function itself, mean

  • A call to the function with . as a dummy argument, mean(., na.rm = TRUE)

These arguments are automatically quoted. They support unquoting and splicing. See vignette("programming") for an introduction to these concepts.

The following notations are not supported, see examples:

  • An anonymous function, function(x) mean(x, na.rm = TRUE)

  • An anonymous function in purrr notation, ~mean(., na.rm = TRUE)

.args, args

A named list of additional arguments to be added to all function calls. As funs() is being deprecated, use other methods to supply arguments: ... argument in scoped verbs or make own functions with purrr::partial().

Details

Soft-deprecated lifecycle

Examples

funs(mean, "mean", mean(., na.rm = TRUE))
#> Warning: funs() is soft deprecated as of dplyr 0.8.0 #> Please use a list of either functions or lambdas: #> #> # Simple named list: #> list(mean = mean, median = median) #> #> # Auto named with `tibble::lst()`: #> tibble::lst(mean, median) #> #> # Using lambdas #> list(~ mean(., trim = .2), ~ median(., na.rm = TRUE)) #> This warning is displayed once per session.
#> <fun_calls> #> $ mean: mean(.) #> $ mean: mean(.) #> $ mean: mean(., na.rm = TRUE)
# Override default names funs(m1 = mean, m2 = "mean", m3 = mean(., na.rm = TRUE))
#> <fun_calls> #> $ m1: mean(.) #> $ m2: mean(.) #> $ m3: mean(., na.rm = TRUE)
# If you have function names in a vector, use funs_ fs <- c("min", "max") funs_(fs)
#> Warning: funs_() is deprecated. #> Please use list() instead #> This warning is displayed once per session.
#> <fun_calls> #> $ min: min(.) #> $ max: max(.)
# Not supported if (FALSE) { funs(function(x) mean(x, na.rm = TRUE)) funs(~mean(x, na.rm = TRUE))}