rlang (version 0.1.2)

dots_definitions: Tidy quotation of multiple expressions and dots

Description

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

Usage

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

Run this code
# NOT RUN {
# 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
# }

Run the code above in your browser using DataCamp Workspace