[R] on lexical scoping....

Richard O'Keefe r@oknz @end|ng |rom gm@||@com
Wed Apr 5 07:00:38 CEST 2023


R *does* search the environment stack.

> search()
[1] ".GlobalEnv"        "package:stats"     "package:graphics"
[4] "package:grDevices" "package:utils"     "package:datasets"
[7] "package:methods"   "Autoloads"         "package:base

What you seem to be missing is that a package may contain
bindings that it does not export, as the wording of this
error message reminds us:
> utils::y
Error: 'y' is not an exported object from 'namespace:utils'

So when package/namespace goes onto the environment stack,
it's only the *exported* bindings that become visible.



On Wed, 5 Apr 2023 at 01:56, akshay kulkarni <akshay_e4 using hotmail.com> wrote:

> 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. 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
> https://stat.ethz.ch/mailman/listinfo/r-help
> PLEASE do read the posting guide
> http://www.R-project.org/posting-guide.html
> and provide commented, minimal, self-contained, reproducible code.
>

	[[alternative HTML version deleted]]



More information about the R-help mailing list