3

could someone please explain to me what these various environment functions do specifically? ie which one returns what frame? i am thoroughly confused after reading the documentation (http://stat.ethz.ch/R-manual/R-patched/library/base/html/sys.parent.html)

Let's put some structure on the question:

x = 1; y=2; z=3;
f = function() { ls(); ls(envir=sys.frame());}
#this first prints the contents of this function and then of the global environment

I am trying to understand how one can access environments of calling functions and to know which environment you are in. For example g could have called f:

g = function() { somevar=1; f() }

If I wanted to get the contents of g, how would i do that? What is the difference between a frame and an environment?

4

1 に答える 1

2

parent.frame()呼び出し環境を指します。通常、残りは必要ありません。あなたの例では、これを使用してリストしますsomevar

f <- function() ls(parent.frame())
于 2013-01-23T23:32:50.707 に答える