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!