friendlyeval (version 0.1.1)

treat_string_as_expr: treat_string_as_expr(x)

Description

Treat the string value of a variable as an expression in a dplyr function.

Usage

treat_string_as_expr(x)

Arguments

x

a string to be treated as an expression.

Value

something that will resolve to an expression when prefixed with `!!`

Details

This will parse a string and treat it as an expression to be evaluated in the context of a dplyr function call. This may be convenient when building expressions to evaluate at run-time.

Examples

Run this code
# NOT RUN {
## processing operations from other notation 
calc_result <- function(dat, operation){
  operation <- gsub('x', '*', operation)
  mutate(dat, result = !!treat_string_as_expr(operation))
}

calc_result(mtcars, "mpg x hp")
# }
# NOT RUN {
# }

Run the code above in your browser using DataCamp Workspace