sys.parent(base)
sys.parent()所属R语言包:base
Functions to Access the Function Call Stack
函数调用堆栈函数来访问
译者:生物统计家园网 机器人LoveR
描述----------Description----------
These functions provide access to environments ("frames" in S terminology) associated with functions further up the calling stack.
这些功能提供environment(“框架”中的术语),功能最多的调用堆栈进一步的访问。
用法----------Usage----------
sys.call(which = 0)
sys.frame(which = 0)
sys.nframe()
sys.function(which = 0)
sys.parent(n = 1)
sys.calls()
sys.frames()
sys.parents()
sys.on.exit()
sys.status()
parent.frame(n = 1)
参数----------Arguments----------
参数:which
the frame number if non-negative, the number of frames to go back if negative.
如果非负的帧数,帧数回去如果是负数。
参数:n
the number of generations to go back. (See the "Details" section.)
代回去。 (见“详细资料”部分。)
Details
详情----------Details----------
.GlobalEnv is given number 0 in the list of frames. Each subsequent function evaluation increases the frame stack by 1 and the call, function definition and the environment for evaluation of that function are returned by sys.call, sys.function and sys.frame with the appropriate index.
.GlobalEnv给定数量的帧列表0。每个后续功能评估增加1帧栈和调用,函数的定义和环境评价该函数返回由sys.call,sys.function和sys.frame适当的索引。
sys.call, sys.frame and sys.function accept integer values for the argument which. Non-negative values of which are frame numbers whereas negative values are counted back from the frame number of the current evaluation.
sys.call,sys.frame和sys.function接受整数参数which值。非负值which帧号,而负值计算帧数量从目前的评价。
The parent frame of a function evaluation is the environment in which the function was called. It is not necessarily numbered one less than the frame number of the current evaluation, nor is it the environment within which the function was defined. sys.parent returns the number of the parent frame if n is 1 (the default), the grandparent if n is 2, and so on. See also the "Note".
父框架的功能评价是在该函数被称为环境。它不一定编号帧的数量比目前评价少,也不是它的环境,在定义该函数。 sys.parent返回父帧的数量,如果n是1(默认),祖父母,如果n是2,依此类推。也见“注”。
sys.nframe returns an integer, the number of the current frame as described in the first paragraph.
sys.nframe返回一个整数,当前帧的数量,如在第一款所述。
sys.calls and sys.frames give a pairlist of all the active calls and frames, respectively, and sys.parents returns an integer vector of indices of the parent frames of each of those frames.
sys.calls和sys.frames给所有的积极呼吁和框架pairlist,分别sys.parents返回一个整数向量每个帧的父帧指数。
Notice that even though the sys.xxx functions (except sys.status) are interpreted, their contexts are not counted nor are they reported. There is no access to them.
请注意,即使sys.XXX功能(除了sys.status)解释,上下文不计算在内,也不是他们的报告。有没有对他们的访问。
sys.status() returns a list with components sys.calls, sys.parents and sys.frames, the results of calls to those three functions (which this will include the call to sys.status: see the first example).
sys.status()返回一个组件的列表sys.calls,sys.parents和sys.frames,调用这三个函数(这将包括呼叫sys.status的结果:看到的第一个例子)。
sys.on.exit() returns the expression stored for use by on.exit in the function currently being evaluated. (Note that this differs from S, which returns a list of expressions for the current frame and its parents.)
sys.on.exit()返回on.exit目前正在评估在功能使用存储的表达。 (请注意,这从S,它返回当前帧和其父母的表情列表不同。)
parent.frame(n) is a convenient shorthand for sys.frame(sys.parent(n)) (implemented slightly more efficiently).
parent.frame(n)sys.frame(sys.parent(n))(略更有效地实施)为方便的速记。
值----------Value----------
sys.call returns a call, sys.function a function definition, and sys.frame and parent.frame return an environment.
sys.call返回一个电话,sys.function函数的定义,sys.frame和parent.frame返回的环境。
For the other functions, see the "Details" section.
对于其他功能,请参阅“详细资料”一节。
注意----------Note----------
Strictly, sys.parent and parent.frame refer to the context of the parent interpreted function. So internal functions (which may or may not set contexts and so may or may not appear on the call stack) may not be counted, and S3 methods can also do surprising things.
严格来说,sys.parent和parent.frame解释父功能方面。因此,内部功能(可能或可能不被计算,S3的方法也可以做奇怪的事情,可能没有设置背景和可能或可能不会出现在调用堆栈上)。
Beware of the effect of lazy evaluation: these two functions look at the call stack at the time they are evaluated, not at the time they are called. Passing calls to them as function arguments is unlikely to be a good idea.
谨防懒惰的评价效果:看一下这两个函数在调用堆栈在他们所评估的时间,没有时间,他们被称为。通过调用它们作为函数的参数是不太可能是一个好主意。
参考文献----------References----------
The New S Language. Wadsworth & Brooks/Cole. (Not <code>parent.frame</code>.)
参见----------See Also----------
eval for a usage of sys.frame and parent.frame.
eval为sys.frame和parent.frame使用。
举例----------Examples----------
require(utils)
## Note: the first two examples will give different results[#注:前两个例子会得出不同的结果]
## if run by example().[#如果运行(例如)。]
ff <- function(x) gg(x)
gg <- function(y) sys.status()
str(ff(1))
gg <- function(y) {
ggg <- function() {
cat("current frame is", sys.nframe(), "\n")
cat("parents are", sys.parents(), "\n")
print(sys.function(0)) # ggg[GGG]
print(sys.function(2)) # gg[GG]
}
if(y > 0) gg(y-1) else ggg()
}
gg(3)
t1 <- function() {
aa <- "here"
t2 <- function() {
## in frame 2 here[#在第2帧在这里]
cat("current frame is", sys.nframe(), "\n")
str(sys.calls()) ## list with two components t1() and t2()[#列表T1两部分组成的()和T2()]
cat("parents are frame numbers", sys.parents(), "\n") ## 0 1[#0 1]
print(ls(envir=sys.frame(-1))) ## [1] "aa" "t2"[#[1]“AA”,“T2”]
invisible()
}
t2()
}
t1()
test.sys.on.exit <- function() {
on.exit(print(1))
ex <- sys.on.exit()
str(ex)
cat("exiting...\n")
}
test.sys.on.exit()
## gives 'language print(1)', prints 1 on exit[#给出的语言打印(1)“1,打印退出]
## An example where the parent is not the next frame up the stack[#一个例子,其中父母是不是堆栈的下一帧]
## since method dispatch uses a frame.[#因为调度方法使用了一个框架。]
as.double.foo <- function(x)
{
str(sys.calls())
print(sys.frames())
print(sys.parents())
print(sys.frame(-1)); print(parent.frame())
x
}
t2 <- function(x) as.double(x)
a <- structure(pi, class = "foo")
t2(a)
转载请注明:出自 生物统计家园网(http://www.biostatistic.net)。
注:
注1:为了方便大家学习,本文档为生物统计家园网机器人LoveR翻译而成,仅供个人R语言学习参考使用,生物统计家园保留版权。
注2:由于是机器人自动翻译,难免有不准确之处,使用时仔细对照中、英文内容进行反复理解,可以帮助R语言的学习。
注3:如遇到不准确之处,请在本贴的后面进行回帖,我们会逐渐进行修订。
|