Question Details

No question body available.

Tags

r dplyr tidyverse rlang

Answers (2)

Accepted Answer Available
Accepted Answer
July 7, 2026 Score: 3 Rep: 35,945 Quality: Expert Completeness: 80%

As noted in Konrad's answer, you can use rlang::enquos() to capture the ... arguments as a list of quosures, which you can then iterate over like any regular list. Each element can be injected back into dplyr verbs with !! and converted to a string name with rlang::aslabel():

library(dplyr)

myfunc # A tibble: 150 × 7 #> # Groups: Sepal.Length [35] #> Sepal.Length Sepal.Width Petal.Length Petal.Width Species Sepal.Widthmean #> #> 1 5.1 3.5 1.4 0.2 setosa 3.5 #> 2 4.9 3 1.4 0.2 setosa 3 #> 3 4.7 3.2 1.3 0.2 setosa 3.2 #> 4 4.6 3.1 1.5 0.2 setosa 3.1 #> 5 5 3.6 1.4 0.2 setosa 3.6 #> 6 5.4 3.9 1.7 0.4 setosa 3.9 #> 7 4.6 3.4 1.4 0.3 setosa 3.4 #> 8 5 3.4 1.5 0.2 setosa 3.4 #> 9 4.4 2.9 1.4 0.2 setosa 2.9 #> 10 4.9 3.1 1.5 0.1 setosa 3.1 #> # ℹ 140 more rows #> # ℹ 1 more variable: Sepal.Lengthmean

Created on 2026-07-07 with reprex v2.1.1

Here, rlang::enquos(...) captures all ... arguments as unevaluated quosures, then iterating over the list gives you one quosure per variable. !!var injects the quosure back into dplyr verbs (groupby, mutate, etc.). rlang::aslabel(var) extracts the variable name as a string for naming new columns. And finally := is needed on the left-hand side of mutate when the column name is computed programmatically.

This is equivalent to your working version but allows bare unquoted variable names in the function call.

You could also use purrr::reduce and (ab)use across and its .names variable;

myfunc mutate(across(!!var, mean, .names = "{.col}
mean")) }, .init = data) }
July 7, 2026 Score: 4 Rep: 550,710 Quality: Medium Completeness: 70%

The relevant documentation can be found in the ‘rlang’ package under dynamic dots (it’s linked from the other documentation you read).

In a nutshell, you can use rlang::enquos() to capture unevaluated (“defused”) expressions passed as arguments, and you can use the splice operator !!! in place of {{…}} to inject them into supporting functions:

mygroup