eval_text {evalR}R Documentation

safely evaluate text

Description

Safe alternative to using eval + parse

Usage

eval_text(
  text,
  singular_operators = NULL,
  binary_operators = NULL,
  valid_functions = NULL,
  map = NULL,
  mapping_names = NULL
)

Arguments

text

the string/code/statement you want to parse.

singular_operators

tokens of length 1 that operate on a right hand value. For example, the '-' token is an operator to negate a vector. NULL value will be replaced with c("-", "!").

binary_operators

tokens of any length that operate on a left and right hand values. For example, the '+' token is an operator that adds a left vector to a right vector. NULL value will be replaced with c(",", "|", "&", "<=", "<", ">=", ">", "==", "!=", "+", "-", "*", "%/%", "/", "%%", "%in%", ":", "^"). The order determines the precedence of the operators.

valid_functions

tokens of any length that are prefixed on a parenthesis block and specify a function to run on the provided parameters within the block. For example, the 'log' token will evaluate the logarithm value of the first parameter. Note named parameters are not support. NULL value will be replaced with c("log", "c", "any", "all", "abs", "ifelse").

map

a named list of data.frames/lists/matrices. Where names are keys for referencing the values in the text parameters.

mapping_names

optional argument to make the function faster or limit which map elements can be referenced.

Details

See vignette("Overview", package = "evalR")

Value

numeric or logical vector

Examples

eval_text("1 + 2")

# using the map parameter 
map_obj <- list("#" = data.frame(x = 1:5, y = 5:1),"$" = list(z = -(1:5)))
y <- evalR::eval_text("#x# + $z$", map=map_obj)

[Package evalR version 0.0.1 Index]