如何在R中获取变量的环境 [英] How to get environment of a variable in R
本文介绍了如何在R中获取变量的环境的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我想知道是否有任何方法可以获得声明变量的环境.假设我已经向环境声明了一个变量,并且想使用该变量的环境来声明更多变量.类似 getEnv("variable")
I was wondering if there is anyway to get the environment of a declared variable. Say I already have declared a variable to an environment and want to use that variable's environment to declare a few more variables. Something like getEnv("variable")
推荐答案
参考:http://adv-r.had.co.nz/Environments.html#env-basics
library(pryr)
x <- 5
where("x")
#> <environment: R_GlobalEnv>
where("mean")
#> <environment: base>
where 函数在上面的网站中有描述.它只找到变量出现的第一个环境,但可以轻松修改以找到所有环境.
The where function is described in the above website. It only finds the first environment the variable appears in, but could easily be modified to find all.
这篇关于如何在R中获取变量的环境的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文