This function evaluates a string as R code, and stops if an error occurs.
This can be useful for evaluating code that is generated dynamically.
However, usually the best and most secure practice is to use quasi-quotation
instead.
Arguments
- ...
the R code to evaluate as characters. Will be joined when
evaluating.
- envir
the environment in which to evaluate the code. Defaults to the
parent frame of the function.
Value
the result of the evaluation
Examples
# Set names of a vector
x <- 1:3
x <- evalText("setNames(x, c('A', 'B', 'C'))")
x
#> A B C
#> 1 2 3