R-alpha: Environment strangeness

Martin Maechler Martin Maechler <maechler@stat.math.ethz.ch>
Tue, 5 Aug 1997 16:22:24 +0200


If you look at the new  'eval' man page that comes with the  a1-->a2
patches, you see that R or R has added a paragraph that somewhat resembles
your proposal.

PD> This belongs on the *manual page*. I suggest something along these
PD> lines:

PD> NOTE( Calling LANG(eval(x+y,e)) does not do what one might think. To
PD> get values of LANG(x) and LANG(y) looked up in the environment
PD> LANG(e), use LANG(eval(expression(x+y),e)). The logic is that
PD> LANG(expr) is usually a simple variable ITALIC(containing) an
PD> expression to evaluate or a LANG(substitute(...)) call
PD> ITALIC(resulting) in an expression. Hence, the value of LANG(expr) is
PD> passed to the evaluator.
PD> )

They don't use any pejorative words such as "counterintuitive" though... ;-)

help(eval)>  The expression expr is evaluated in the environment
help(eval)>  that eval is called from. This allows you to assign
help(eval)>  complicated expressions to symbols and then evaluate
help(eval)>  them. If you want to evaluate expr in envir then you
help(eval)>  must wrap a call to expression around it.
	
  and later

help(eval)> 	Examples:

	     ....

help(eval)> 	     tst.ev <- function(a = 7) { x <- pi; y <- 1; ev() }
help(eval)> 	     ev <- function() {
help(eval)> 	          e1 <- sys.frame(sys.parent())
help(eval)> 	          ## Evaluate a in e1
help(eval)> 	          aa <- eval(expression(a),e1)
help(eval)> 	          ## evaluate the expression bound to a in e1
help(eval)> 	          a <- expression(x+y)
help(eval)> 	          list(aa = aa, eval = eval(a, e1))
help(eval)> 	     }
help(eval)> 	     tst.ev()#-> aa : 7,  eval : 4.14
	
	[R&R: The example was improved by me:  
	      ALL examples should be self-contained executable !]

-- Martin
=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-
r-devel mailing list -- Read http://www.ci.tuwien.ac.at/~hornik/R/R-FAQ.html
Send "info", "help", or "[un]subscribe"
(in the "body", not the subject !)  To: r-devel-request@stat.math.ethz.ch
=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-