The substitute function can be substituted into environment-bound values. It is strange that its argument env does not have a default value, but by default it belongs to the evaluation environment. It seems that this behavior does not work when the evaluation environment is a global environment, but otherwise works fine.
Here is an example:
> a = new.env() > a$f = function(x){x^2} > substitute(f, a) function(x){x^2} > f = function(x){x^2} > environment() <environment: R_GlobalEnv> > substitute(f, environment()) f > substitute(f, globalenv()) f
As shown, when using the global environment as the second argument, the function does not work.
Another demonstration that it works correctly using a , but not a global environment:
> evalq(substitute(f), a) function(x){x^2} > evalq(substitute(f), environment()) f
Pretty strange.
source share