[R] converting character strings to eval

Deepayan Sarkar deepayan at stat.wisc.edu
Tue Jul 20 15:05:32 CEST 2004


On Tuesday 20 July 2004 06:19, John Hendrickx wrote:

> Couldn't eval be modified to automatically parse arguments if they're
> not expressions? Something like:
> eval2<-function(arg) {
> 	if (!is.expression(arg)) arg<-parse(text=arg)
> 	eval(arg)
> }
> Would a construction like eval2 have a downside or cause problems
> down the line?

If eval itself is modified, that would cause backward incompatibilities. 
e.g.,

> k = "mystring"
> eval(k)
[1] "mystring"
> eval2(k)
Error in eval(expr, envir, enclos) : Object "mystring" not found

Deepayan




More information about the R-help mailing list