[R] on lexical scoping....
deep@y@n@@@rk@r @end|ng |rom gm@||@com
Tue Apr 4 16:21:20 CEST 2023
On Tue, Apr 4, 2023 at 7:26 PM akshay kulkarni <akshay_e4 using hotmail.com>
> Dear Members,
> I have the following code typed at the
> console prompt:
> y <- x*10
> X has not been defined and the above code throws an object not found
> error. That is, the global environment does not contain x.
That is not the correct interpretation of the error. R will happily evaluate
y <- pi*10
even if the global environment does not contain pi. The "environments"
where R will look is given by
If you manage to find a package that defines 'x' (and exports it),
attaching it will put the package on the search path, and then your call
will indeed no longer give an error.
Why doesn't it look further in the environment stack, like that of
> packages? There are thousands of packages that contain the variable named
> x. Of course, that happens if the above code is in a function (or does it?).
> What concept of R is at work in this dichotomy?
> THanking you,
> Yours sincerely,
> AKSHAY M KULKARNI
> [[alternative HTML version deleted]]
> R-help using r-project.org mailing list -- To UNSUBSCRIBE and more, see
> PLEASE do read the posting guide
> and provide commented, minimal, self-contained, reproducible code.
[[alternative HTML version deleted]]
More information about the R-help