Learn R Programming

wrapr (version 1.0.1)

beval: Evaluate an expression with (!!name) and := to = substitution.

Description

The expression represented by the text of the .-argument is evaluated in the current environment will all "(!!name)" forms replaced by the value of name. Note: this substitution can only be performed on the right hand side of assignments. This allows variables to carry the names of other variables into what would be a non-standard evaluation situation. This adaption allows some parametric or standard-evaluation effects in such circumstances.

Usage

beval(...)

Arguments

...

expression or block to evaluate

Details

Note: this method uses string substitution and is willing to substitute in arbitrary content, please prefer using let where applicable.

Notation idea: https://github.com/hadley/dplyr/commit/8f03f835185370626a566e95d268623b20189e07. Note: "!!" is not a no-op, but is a sufficiently uncommon expression I thought we could use it.

See Also

let, ateval, seval

Examples

Run this code
# NOT RUN {

c1 <- 1:5
c2 <- 3:7
col1 <- 'c1'
col2 <- 'c2'
beval(
  res <- (!!col1) + (!!col2)
)
print(res)

# larger example
c3 <- 4:8
terms <- paste(c('c1', 'c2', 'c3'), collapse = ' + ')
print(beval((!!terms)))

# }

Run the code above in your browser using DataLab