quos() quotes its arguments and returns them as a list of quosures (see quo()). It is especially useful to capture arguments forwarded through ....

dots_definitions(..., .named = FALSE)

quos(..., .named = FALSE, .ignore_empty = c("trailing", "none", "all"))

is_quosures(x)

Arguments

...

Expressions to capture unevaluated.

.named

Whether to ensure all dots are named. Unnamed elements are processed with expr_text() to figure out a default name. If an integer, it is passed to the width argument of expr_text(), if TRUE, the default width is used. See exprs_auto_name().

.ignore_empty

Whether to ignore empty arguments. Can be one of "trailing", "none", "all". If "trailing", only the last argument is ignored if it is empty.

x

An object to test.

Details

Both quos and dots_definitions() have specific support for definition expressions of the type var := expr, with some differences:

quos()

When := definitions are supplied to quos(), they are treated as a synonym of argument assignment =. On the other hand, they allow unquoting operators on the left-hand side, which makes it easy to assign names programmatically.

dots_definitions()

This dots capturing function returns definitions as is. Unquote operators are processed on capture, in both the LHS and the RHS. Unlike quos(), it allows named definitions.

Examples

# quos() is like the singular version but allows quoting # several arguments: quos(foo(), bar(baz), letters[1:2], !! letters[1:2])
#> [[1]] #> <quosure: local> #> ~foo() #> #> [[2]] #> <quosure: local> #> ~bar(baz) #> #> [[3]] #> <quosure: local> #> ~letters[1:2] #> #> [[4]] #> <quosure: empty> #> ~c("a", "b") #> #> attr(,"class") #> [1] "quosures"
# It is most useful when used with dots. This allows quoting # expressions across different levels of function calls: fn <- function(...) quos(...) fn(foo(bar), baz)
#> [[1]] #> <quosure: local> #> ~foo(bar) #> #> [[2]] #> <quosure: local> #> ~baz #> #> attr(,"class") #> [1] "quosures"
# Note that quos() does not check for duplicate named # arguments: fn <- function(...) quos(x = x, ...) fn(x = a + b)
#> $x #> <quosure: local> #> ~x #> #> $x #> <quosure: local> #> ~a + b #> #> attr(,"class") #> [1] "quosures"
# Dots can be spliced in: args <- list(x = 1:3, y = ~var) quos(!!! args, z = 10L)
#> $x #> <quosure: empty> #> ~1:3 #> #> $y #> <quosure: local> #> ~~var #> #> $z #> <quosure: empty> #> ~10L #> #> attr(,"class") #> [1] "quosures"
# Raw expressions are turned to formulas: args <- alist(x = foo, y = bar) quos(!!! args)
#> $x #> <quosure: local> #> ~foo #> #> $y #> <quosure: local> #> ~bar #> #> attr(,"class") #> [1] "quosures"
# Definitions are treated similarly to named arguments: quos(x := expr, y = expr)
#> $x #> <quosure: local> #> ~expr #> #> $y #> <quosure: local> #> ~expr #> #> attr(,"class") #> [1] "quosures"
# However, the LHS of definitions can be unquoted. The return value # must be a symbol or a string: var <- "foo" quos(!!var := expr)
#> $foo #> <quosure: local> #> ~expr #> #> attr(,"class") #> [1] "quosures"
# If you need the full LHS expression, use dots_definitions(): dots <- dots_definitions(var = foo(baz) := bar(baz)) dots$defs
#> $var #> $var$lhs #> <quosure: local> #> ~foo(baz) #> #> $var$rhs #> <quosure: local> #> ~bar(baz) #> #>