dots_definitions {rlang} | R Documentation |
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)
... |
Expressions to capture unevaluated. |
.named |
Whether to ensure all dots are named. Unnamed
elements are processed with |
.ignore_empty |
Whether to ignore empty arguments. Can be one
of |
x |
An object to test. |
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.
# quos() is like the singular version but allows quoting # several arguments: quos(foo(), bar(baz), letters[1:2], !! letters[1:2]) # 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) # Note that quos() does not check for duplicate named # arguments: fn <- function(...) quos(x = x, ...) fn(x = a + b) # Dots can be spliced in: args <- list(x = 1:3, y = ~var) quos(!!! args, z = 10L) # Raw expressions are turned to formulas: args <- alist(x = foo, y = bar) quos(!!! args) # Definitions are treated similarly to named arguments: quos(x := expr, y = expr) # However, the LHS of definitions can be unquoted. The return value # must be a symbol or a string: var <- "foo" quos(!!var := expr) # If you need the full LHS expression, use dots_definitions(): dots <- dots_definitions(var = foo(baz) := bar(baz)) dots$defs