What the difference between .Golbalenv and package:base?
As you know, in the search path, there is .GlobalEnv, package:stats and so on, why do we need to convert the character "package:stats" to the stats environment. I mean, why don't let package:stats be a environment type object like .GlobalEnv,but let it be a string ? Hope you understand my meaning for my pool english expression way. -- PO SU mail: desolator88 at 163.com Majored in Statistics from SJTU
At 2014-08-25 09:53:37, "John McKown" <john.archie.mckown at gmail.com> wrote:
On Mon, Aug 25, 2014 at 1:07 AM, PO SU <rhelpmaillist at 163.com> wrote:
Dear rusers,
As we know, there are a lot of environments in the search() path, such as .Golbalenv and package:base .
And i can just use .Golbalenv$a ,.Golbalenv$b to use the virable, but i must use as.envrionment("package:base") to find virable, i feel it not very convenient.
For example, when i use the following codes to add a new env into the search() path.
tmp<-attach(NULL,name="new_name")
assign("a",2,envir=as.environment("new_name"))
a
[1] 2
as.environment("new_name")$a
[1] 2 I must always convert the name to the environment, How can i just use the following form:
tmp<-attach(NULL,name="new_name")
assign("a",2,envir=new_name) #like using .GlobalEnv
a
[1] 2
new_name$a
[1] 2 -- PO SU mail: desolator88 at 163.com Majored in Statistics from SJTU
You might want to try:
new_name <- new.env();
# or if you prefer (such as in a function)
assign("new_name",new.env(),envir=.GlobalEnv);
#
# You may now assign variable into this similar to:
new_name$a <- 2;
gvar <- new_name$a; # get the variable a from environment new_name
gvar <- get("a",envir=new_name); #same thing, but wordy
attach(new_name);
a
gvar <- a;
--
There is nothing more pleasant than traveling and meeting new people!
Genghis Khan
Maranatha! <><
John McKown