evalText: evaluates a string as R code, and stops if an error occurs

View source: R/metaProgramming.R

evalTextR Documentation

evaluates a string as R code, and stops if an error occurs

Description

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.

Usage

evalText(..., envir = parent.frame())

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


FastUtils documentation built on Sept. 11, 2024, 5:13 p.m.