funs: Create a list of function calls

Description Usage Arguments Examples

View source: R/deprec-funs.R

Description

\Sexpr[results=rd, stage=render]{lifecycle::badge("deprecated")}

funs() is deprecated; please use list() instead. We deprecated this function because it provided a unique way of specifying anonymous functions, rather than adopting the conventions used by purrr and other packages in the tidyverse.

Usage

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

Arguments

...

<data-masking> 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)

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().

Examples

1
2
3
4
5
6
7
funs("mean", mean(., na.rm = TRUE))
# ->
list(mean = mean, mean = ~ mean(.x, na.rm = TRUE))

funs(m1 = mean, m2 = "mean", m3 = mean(., na.rm = TRUE))
# ->
list(m1 = mean, m2 = "mean", m3 = ~ mean(.x, na.rm = TRUE))

Example output

Attaching package: 'dplyr'

The following objects are masked from 'package:stats':

    filter, lag

The following objects are masked from 'package:base':

    intersect, setdiff, setequal, union

<fun_calls>
$ mean: mean(.)
$ mean: mean(., na.rm = TRUE)
Warning message:
funs() is soft deprecated as of dplyr 0.8.0
please use list() instead

# Before:
funs(name = f(.)

# After: 
list(name = ~f(.))
This warning is displayed once per session. 
$mean
function (x, ...) 
UseMethod("mean")
<bytecode: 0x3253130>
<environment: namespace:base>

$mean
~mean(.x, na.rm = TRUE)

<fun_calls>
$ m1: mean(.)
$ m2: mean(.)
$ m3: mean(., na.rm = TRUE)
$m1
function (x, ...) 
UseMethod("mean")
<bytecode: 0x3253130>
<environment: namespace:base>

$m2
[1] "mean"

$m3
~mean(.x, na.rm = TRUE)

dplyr documentation built on June 19, 2021, 1:07 a.m.