Capture ... (dots) for later lazy evaluation.

lazy_dots(..., .follow_symbols = FALSE, .ignore_empty = FALSE)

Arguments

...

Dots from another function

.follow_symbols

If TRUE, the default, follows promises across function calls. See vignette("chained-promises") for details.

.ignore_empty

If TRUE, empty arguments will be ignored.

Value

A named list of lazy expressions.

Examples

lazy_dots(x = 1)
#> $x
#> <lazy>
#>   expr: 1
#>   env:  <environment: 0x5636a3dc56c0>
#> 
#> attr(,"class")
#> [1] "lazy_dots"
lazy_dots(a, b, c * 4)
#> [[1]]
#> <lazy>
#>   expr: a
#>   env:  <environment: 0x5636a3dc56c0>
#> 
#> [[2]]
#> <lazy>
#>   expr: b
#>   env:  <environment: 0x5636a3dc56c0>
#> 
#> [[3]]
#> <lazy>
#>   expr: c * 4
#>   env:  <environment: 0x5636a3dc56c0>
#> 
#> attr(,"class")
#> [1] "lazy_dots"

f <- function(x = a + b, ...) {
  lazy_dots(x = x, y = a + b, ...)
}
f(z = a + b)
#> $x
#> <lazy>
#>   expr: x
#>   env:  <environment: 0x5636a3fca680>
#> 
#> $y
#> <lazy>
#>   expr: a + b
#>   env:  <environment: 0x5636a3fca680>
#> 
#> $z
#> <lazy>
#>   expr: a + b
#>   env:  <environment: 0x5636a3dc56c0>
#> 
#> attr(,"class")
#> [1] "lazy_dots"
f(z = a + b, .follow_symbols = TRUE)
#> $x
#> <lazy>
#>   expr: a + b
#>   env:  <environment: 0x5636a408f4c0>
#> 
#> $y
#> <lazy>
#>   expr: a + b
#>   env:  <environment: 0x5636a408f4c0>
#> 
#> $z
#> <lazy>
#>   expr: a + b
#>   env:  <environment: 0x5636a3dc56c0>
#> 
#> attr(,"class")
#> [1] "lazy_dots"

# .follow_symbols is off by default because it causes problems
# with lazy loaded objects
lazy_dots(letters)
#> [[1]]
#> <lazy>
#>   expr: letters
#>   env:  <environment: 0x5636a3dc56c0>
#> 
#> attr(,"class")
#> [1] "lazy_dots"
lazy_dots(letters, .follow_symbols = TRUE)
#> [[1]]
#> <lazy>
#>   expr: letters
#>   env:  <environment: 0x5636a3dc56c0>
#> 
#> attr(,"class")
#> [1] "lazy_dots"

# You can also modify a dots like a list. Anything on the RHS will
# be coerced to a lazy.
l <- lazy_dots(x = 1)
l$y <- quote(f)
l[c("y", "x")]
#> $y
#> <lazy>
#>   expr: f
#>   env:  <environment: 0x5636a3dc56c0>
#> 
#> $x
#> <lazy>
#>   expr: 1
#>   env:  <environment: 0x5636a3dc56c0>
#> 
#> attr(,"class")
#> [1] "lazy_dots"
l["z"] <- list(~g)

c(lazy_dots(x = 1), lazy_dots(f))
#> $x
#> <lazy>
#>   expr: 1
#>   env:  <environment: 0x5636a3dc56c0>
#> 
#> [[2]]
#> <lazy>
#>   expr: f
#>   env:  <environment: 0x5636a3dc56c0>
#> 
#> attr(,"class")
#> [1] "lazy_dots"