Bug 14902 - substitute() not behaving as explained in ?delayedAssign when object in .GlobalEnv
Summary: substitute() not behaving as explained in ?delayedAssign when object in .Glob...
Status: NEW
Alias: None
Product: R
Classification: Unclassified
Component: Documentation (show other bugs)
Version: R 2.15.0
Hardware: All All
: P5 minor
Assignee: R-core
URL:
Depends on:
Blocks:
 
Reported: 2012-05-01 19:31 UTC by Philippe Grosjean
Modified: 2012-05-01 19:31 UTC (History)
0 users

See Also:


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Philippe Grosjean 2012-05-01 19:31:55 UTC
substitute() used on a promise created by delayedAssign() in .GlobalEnv does not return the expression associated with the promise, as stated in "see also"

This fails in example(delayedAssign) too, and it seems someone was already surprised by this, since there is a comment at the problematic line:

substitute(x) #- x (was 'msg' ?)

?substitute is not clear too here:

"Substitution takes place by examining each component of the parse tree as follows: If it is not a bound symbol in env, it is unchanged. If it is a promise object, i.e., a formal argument to a function or explicitly created using delayedAssign(), the expression slot of the promise replaces the symbol. If it is an ordinary variable, its value is substituted, unless env is .GlobalEnv in which case the symbol is left unchanged."

This suggests the non-replacement in .GlobalEnv is only occuring for "ordinary variables", not for "promises", which is apparently not the case.

Note that there is currently NO R function to retrieve the expression associated witn R promises in .GlobalEnv. One has to work at C level for that! Isn't it missing?

In C code for substitute, a comment says that non-substitution in .GlobalEnv is for "historical reasons". Are these "historical reasons" still that important to impose such a surprising and weird behavior of substitute()?

At least, the doc has to be fixed? At best, substitute() behavior should be changed!