Find centralized, trusted content and collaborate around the technologies you use most.
Teams
Q&A for work
Connect and share knowledge within a single location that is structured and easy to search.
我想检查当前环境是否是 R 中的全局环境。但是,直接比较似乎不适用于环境。做这个的最好方式是什么?
#doesn't work sys.frame() == .GlobalEnv
马修普洛德的解决方案:
> identical(sys.frame(),.GlobalEnv) [1] TRUE
您也可以检查名称,尽管这可能不太可靠:
> environmentName(sys.frame())=="R_GlobalEnv" [1] TRUE