[R] A question on substitute()

Bert Gunter bgunter@4567 @end|ng |rom gm@||@com
Mon Dec 14 06:36:44 CET 2020


Please disregard my previous post. My understanding is correct, and the
behavior is **AS DOCUMENTED**.
I failed to read the docs carefully. Mea Culpa.

Best,
Bert

Bert Gunter

"The trouble with having an open mind is that people keep coming along and
sticking things into it."
-- Opus (aka Berkeley Breathed in his "Bloom County" comic strip )


On Sun, Dec 13, 2020 at 8:32 PM Bert Gunter <bgunter.4567 using gmail.com> wrote:

> I would appreciate any help in correcting my misunderstanding of the
> following:
>
> > substitute(quote(x+a), env = list(a=5))
> quote(x + 5)  ## as expected
> > substitute(quote(x+a), env = list2env(list(a=5)))
> quote(x + 5)  ## as expected
>
> > ### BUT
> > .GlobalEnv$a
> [1] 5
> > substitute(quote(x+a), env = .GlobalEnv)
> quote(x + a)  ## unexpected
>
> I conclude from this that there is something special about .GlobalEnv that
> does not allow it to behave as documented for the env argument in
> ?substitute, to wit:
>
> "env:
>
> an environment or a list object. Defaults to the current evaluation
> environment."
>
> I would be grateful for any insight, as I am clearly missing something.
>
>
> Note: (though I don't think this matters):
>
> > sessionInfo()
> R version 4.0.3 (2020-10-10)
> Platform: x86_64-apple-darwin17.0 (64-bit)
> Running under: macOS Big Sur 10.16
>
>
> Cheers to all,
>
> Bert
>
> Bert Gunter
>
> "The trouble with having an open mind is that people keep coming along and
> sticking things into it."
> -- Opus (aka Berkeley Breathed in his "Bloom County" comic strip )
>

	[[alternative HTML version deleted]]



More information about the R-help mailing list