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
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
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With