[ top | up ]

Functions to access the function call stack.

Syntax

sys.call(which=<>)
sys.frame(which=<>)
sys.nframe()
sys.function(n=<>)
sys.parent(n=1)

sys.calls()
sys.frames()
sys.parents()
sys.on.exit()

Arguments

which the frame number.
n the number of frame generations to go back.

Description

These functions provide access to environments (frames in S-speak) associated with functions further up the calling stack. You need access to two different types of environments. You need access to the environment where the arguments to a function are defined. This is what sys.parent does. You also need access to the environment where a function is being evaluated this is what sys.frame does.

Often sys.parent is the globalEnv or the top-level environment. This is given number 1 in the list of frames. Each subsequent function evaluation increases the frame stack by 1 and the environment for evaluation of that function is returned by sys.frame with the appropriate index.

sys.call and sys.frame both accept either positive or negative values for the argument which. Positive values of which count up from frame 1 and negative values are count back from frame n.

Notice that even though the sys.xxx functions are interpreted their contexts are not counted nor are they reported. There is no access to them.

sys.status has not been implemented yet.