Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

how to compare environment for equality in R

I would like to check if the current environment is the global environment in R. However, direct comparison doesn't seem to work with evironments. What is the best way to do this?

#doesn't work
sys.frame() == .GlobalEnv
like image 636
Alex Avatar asked Jan 23 '13 23:01

Alex


1 Answers

Matthew Plourde's solution:

> identical(sys.frame(),.GlobalEnv)
[1] TRUE

You can also check names, though this might be less reliable:

> environmentName(sys.frame())=="R_GlobalEnv"
[1] TRUE
like image 108
Jonathan Christensen Avatar answered Sep 18 '22 13:09

Jonathan Christensen