This help topic is for R version 0.64.2. For the current version of R, try https://stat.ethz.ch/R-manual/R-patched/library/base/html/sys.parent.html
sys.parent {base}R Documentation

Functions to access the function call stack.

Description

These functions provide access to environments (“frames” in S-speak) associated with functions further up the calling stack.

Usage

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

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

Arguments

which

the frame number.

n

the number of frame generations to go back.

Details

You need access to two different types of environments.

  1. You need access to the environment where the arguments to a function are defined; this is what sys.parent does.

  2. You also need access to the environment where a function is being evaluated; this is what sys.frame does.

Often sys.parent() is the top-level environment, .GlobalEnv. 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() simply returns a list with components sys.calls, sys.parents, sys.frames. eval for the usage of sys.frame. ff <- function(x) gg(x) gg <- function(y) sys.status() str(ff(1)) programming data


[Package base version 0.64.2 ]