mvb.sys.parent: Functions to Access the Function Call Stack

Description Usage Arguments Details Value Author(s) See Also Examples

Description

These functions are "do what I mean, not what I say" equivalents of the corresponding system functions. The system functions can behave strangely when called in strange ways (primarily inside eval calls). The mvb equivalents behave in a more predictable fashion.

Usage

1
2
3
4
5
6
7
8
9

Arguments

All as per the corresponding system functions, from whole helpfiles the following is taken:

which

the frame number if non-negative, the number of generations to go back if negative. (See the Details section.)

n

the number of frame generations to go back.

definition

a function, by default the function from which match.call is called.

call

an unevaluated call to the function specified by definition, as generated by call.

expr

an expression to evaluate

expand.dots

logical. Should arguments matching ... in the call be included or left as a ... argument?

envir

an environment from which the ... in call are retrieved, if any (as per base::match.call)

Details

Sometimes eval is used to execute statements in another frame. If such statements include calls to the system versions of these routines, the results will probably not be what you want. In technical terms: the same environment will actually appear several times on the call stack (returned by sys.frame()) but with a different calling history each time. The mvb. equivalents look through sys.frames() for the first frame whose environment is identical to the environment they were called from, and base all conclusions on that first frame. To see how in detail, look at the most fundamental function: mvb.sys.parent.

mvbutils pre 2.7 used to include mvb.sys.on.exit as well (to return whatever the on.exit code would be), but I think this was by mistake; the code was actually specific to my debug package (which already has its own substitute), and so I've moved it out of mvbutils.

Value

See the helpfiles for the system functions.

Author(s)

Mark Bravington

See Also

sys.parent, sys.nframe, parent.frame, eval.parent, match.call, nargs, sys.call, sys.function

Examples

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
ff.no.eval <- function() sys.nframe()
ff.no.eval() # 1
ff.system <- function() eval( quote( sys.nframe()), envir=sys.frame( sys.nframe()))
ff.system() # expect 1 as per ff.no.eval, get 3
ff.mvb <- function() eval( quote( mvb.sys.nframe()), envir=sys.frame( sys.nframe()))
ff.mvb() # 1
ff.no.eval <- function(...) sys.call()
ff.no.eval( 27, b=4) # ff.no.eval( 27, b=4)
ff.system <- function(...) eval( quote( sys.call()), envir=sys.frame( sys.nframe()))
ff.system( 27, b=4) # eval( expr, envir, enclos) !!!
ff.mvb <- function(...) eval( quote( mvb.sys.call()), envir=sys.frame( sys.nframe()))
ff.mvb( 27, b=4) # ff.mvb( 27, b=4)

mvbutils documentation built on May 2, 2019, 8:32 a.m.