Skip to content
Prev 343400 / 398506 Next

What the difference between .Golbalenv and package:base?

Put simply,
   .GlobalEnv    stores objects you create
   package:base  contains functions and objects provided by R itself

You don?t need to use   .GlobalEnv$a   to use the variable named a. Just
is ?a? by itself.

 a <- 4
 b <- 2*a
print(a)
print(b)

Not necessary to use
  print(.GlobalEnv$a)

Similarly, to find an object in the base package, just type its name.

I don?t know what you are trying to do, or why you think you have to use
.GlobalEnv$a   
But in more than 20 years of using R for many different tasks, I have
never had to do that.

Furthermore, if you are new to R (which I would guess is the case), it
seems unlikely to me that you need to work with environments or use
attach() or assign(). In the vast majority of cases there are simpler ways
that are easier to understand.

You are aware, I hope, that
  > ls('.GlobalEnv')
  > ls(1)
  > ls()
all return the same result?