how to compare environment for equality in R

可紊 提交于 2019-12-10 12:43:40

问题


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

回答1:


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


来源:https://stackoverflow.com/questions/14491523/how-to-compare-environment-for-equality-in-r

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!