Skip to content
Prev 363325 / 398502 Next

Help with non standard evaluation and require function

On 14/08/2016 5:23 AM, Luca Cerone wrote:
Arguments passed to R functions become a special kind of object known as 
a "promise".  Promises contain two things:  the expression to evaluate, 
and the value of the expression.  The value isn't set at first.  It is 
set by evaluating the expression when you use the argument as a regular 
variable in an expression for the first time.  After that every use of 
it returns the same value, but the expression is retained.

When you call substitute() on an argument "arg", it returns the 
expression.  substitute() also works on other kinds of objects that 
aren't promises; it generally returns their value.  When you use it on a 
complex expression, it returns a new expression with undefined variables 
left alone, recognized variables substituted.
I think your interpretation is right.
The expression in the promise "package" is the expression "pkgname" 
(without quotes).
That's not the value of y, it's the expression in y (which will be the 
same once it is evaluated).  Peter gave an example where they differ, 
here's another:

 > f(1+2)
x + (1 + 2)

Duncan Murdoch