embrace-operator: Embrace operator {{

embrace-operatorR Documentation

Embrace operator ⁠{{⁠

Description

The embrace operator ⁠{{⁠ is used to create functions that call other data-masking functions. It transports a data-masked argument (an argument that can refer to columns of a data frame) from one function to another.

my_mean <- function(data, var) {
  dplyr::summarise(data, mean = mean({{ var }}))
}

Under the hood

⁠{{⁠ combines enquo() and !! in one step. The snippet above is equivalent to:

my_mean <- function(data, var) {
  var <- enquo(var)
  dplyr::summarise(data, mean = mean(!!var))
}

See Also

  • What is data-masking and why do I need {{?

  • Data mask programming patterns


tidyverse/rlang documentation built on Oct. 31, 2024, 5:35 p.m.