Skip to content
Prev 343393 / 398506 Next

What the difference between .Golbalenv and package:base?

On Mon, Aug 25, 2014 at 11:19 AM, PO SU <rhelpmaillist at 163.com> wrote:
Yes, you have  Sorry for my misunderstanding of what were originally
saying. I _think_ that I now understand. The fault is likely my
concentrating on the wrong part of your original email. To test my
ability to understand, I submit the following possibility:
[1] ".GlobalEnv"        "new_name"          "new_name"
"tools:rstudio"
 [5] "package:graphics"  "package:grDevices" "package:utils"
"package:datasets"
 [9] "package:methods"   "Autoloads"         "package:base"
[1] 2
[1] "new_name"
[1] "a"
Note the use of pos= instead of envir=. That seems to be the key here.
I hope this was of more use to you. One problem that I have noticed is
that you can not get to the value of "a" by using "new_name$a", but
must use the get() function like: get('a',pos='new_name');

Please be very aware of the following, very confusing fact:
Referencing a variable can not have the expected results.
[1] ".GlobalEnv"        "new_name"          "tools:rstudio"
"package:stats"
 [5] "package:graphics"  "package:grDevices" "package:utils"
"package:datasets"
 [9] "package:methods"   "Autoloads"         "package:base"
[1] "new_name"
NULL
[1] 2
[1] "x"
[1] 2
If you wanted to use string values in the first two commands above,
then perhaps:
[1] ".GlobalEnv"        "new_name"          "tools:rstudio"
"package:graphics"
 [5] "package:grDevices" "package:utils"     "package:datasets"
"package:methods"
 [9] "Autoloads"         "package:base"
character(0)
[1] "a"
[1] 2
[1] "a"
Likewise you can do:
[1] ".GlobalEnv"        "tools:rstudio"     "package:stats"
"package:graphics"
 [5] "package:grDevices" "package:utils"     "package:datasets"
"package:methods"
 [9] "Autoloads"         "package:base"
[1] "acf"                  "acf2AR"               "add.scope"
  [4] "add1"                 "addmargins"           "aggregate"
  [7] "aggregate.data.frame" "aggregate.ts"         "AIC"
 [10] "alias"                "anova"                "ansari.test"
...
[436] "variable.names"       "varimax"              "vcov"
[439] "weighted.mean"        "weighted.residuals"   "weights"
[442] "wilcox.test"          "window"               "window<-"
[445] "write.ftable"         "xtabs"
function (x, ...)
UseMethod("time")
<bytecode: 0x000000000a4e8b00>
<environment: namespace:stats>
function (x, ...)
UseMethod("time")
<bytecode: 0x000000000a4e8b00>
<environment: namespace:stats>