treat_string_as_expr: treat_string_as_expr(x)

Description Usage Arguments Details Value Examples

Description

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

Usage

1

Arguments

x

a string to be treated as an expression.

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.

Value

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

Examples

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
## 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")

## End(Not run)

MilesMcBain/rlung documentation built on May 21, 2019, 9:22 a.m.