Similar to with()
, but with an interface optimized for specifying single
values, sequential evaluation, and an argument order suitable for piping. Can
be used to avoid cluttering the environment with intermediate values, like a
compact local scope. Inspired by the let
expression in Haskell.
Arguments
- expr
Expression to evaluate. The input is captured before evaluation in a context modified by assignments in
...
.- ...
Name-value pairs to assign in the evaluation context for
expr
. Evaluated sequentially (beforeexpr
); you can refer to assignments from previous arguments in subsequent ones.
Examples
let(x = 1, x + x)
#> [1] 2
# Use earlier assignments
let(x = 2, y = x + 3, y * y)
#> [1] 25
# The equivalent local scope
local({
x <- 2
y <- x + 3
y * y
})
#> [1] 25