找回密码
 注册
查看: 2396|回复: 0

R语言:taskCallback()函数中文帮助文档(中英文对照)

[复制链接]
发表于 2012-2-16 17:38:40 | 显示全部楼层 |阅读模式
taskCallback(base)
taskCallback()所属R语言包:base

                                        Add or Remove a Top-Level Task Callback
                                         添加或删除一个顶层的任务回调

                                         译者:生物统计家园网 机器人LoveR

描述----------Description----------

addTaskCallback registers an R function that is to be called each time a top-level task is completed.
addTaskCallback寄存器R的功能,是被称为每一个顶层的任务完成时。

removeTaskCallback un-registers a function that was registered earlier via addTaskCallback.
removeTaskCallback联合国登记注册早些时候通过addTaskCallback功能。

These provide low-level access to the internal/native mechanism for managing task-completion actions. One can use taskCallbackManager at the S-language level to manage S functions that are called at the completion of each task. This is easier and more direct.
这些提供低级别的访问内部/本地管理任务的完成动作机制。一个可以使用taskCallbackManager管理在每个任务的完成称为S的功能的S-语言水平。这是更方便,更直接。


用法----------Usage----------


addTaskCallback(f, data = NULL, name = character())
removeTaskCallback(id)



参数----------Arguments----------

参数:f
the function that is to be invoked each time a top-level task is successfully completed.  This is called with 5 or 4 arguments depending on whether data is specified or not, respectively. The return value should be a logical value indicating whether to keep the callback in the list of active callbacks or discard it.
成功完成的功能是每次被调用顶层的任务。这是5或4个,分别为参数取决于是否data指定或不叫。返回值应该是一个逻辑值,表明主动回调,回调是否保留或放弃它。


参数:data
if specified, this is the 5-th argument in the call to the callback function f.
如果指定的话,这5个参数是在调用的回调函数f。


参数:id
a string or an integer identifying the element in the internal callback list to be removed. Integer indices are 1-based, i.e the first element is 1. The names of currently registered handlers is available using getTaskCallbackNames and is also returned in a call to addTaskCallback.  
一个字符串或一个整数,确定内部的回调列表中的元素将被删除。整数指数是基于1的,即第一个元素是1。目前已注册的处理程序的名称是可以使用getTaskCallbackNames也是调用addTaskCallback在返回。


参数:name
character: names to be used.
性格:要使用的名称。


Details

详情----------Details----------

Top-level tasks are individual expressions rather than entire lines of input.  Thus an input line of the form expression1 ; expression2 will give rise to 2 top-level tasks.
顶层的任务是个人的表达,而不是整行输入。这样的形式expression1 ; expression2输入线将上升到2顶层的任务。

A top-level task callback is called with the expression for the top-level task, the result of the top-level task, a logical value indicating whether it was successfully completed or not (always TRUE at present), and a logical value indicating whether the result was printed or not.  If the data argument was specified in the call to addTaskCallback, that value is given as the fifth argument.
顶层的任务回调被称为表达顶层的任务,顶层的任务的结果,一个逻辑值,该值指示是否已成功完成或(总是目前TRUE),和一个逻辑值,该值指示结果是否被打印或不。如果被指定在调用dataaddTaskCallback参数,该值是作为第五个参数。

The callback function should return a logical value. If the value is FALSE, the callback is removed from the task list and will not be called again by this mechanism. If the function returns TRUE, it is kept in the list and will be called on the completion of the next top-level task.
回调函数应该返回一个逻辑值。如果该值为FALSE,从任务列表中删除回调,不会被再次呼吁通过这一机制。如果该函数返回TRUE,它被保存在列表中,将被称为未来的顶级任务的完成。


值----------Value----------

addTaskCallback returns an integer value giving  the position in the list of task callbacks that this new callback occupies. This is only the current position of the callback. It can be used to remove the entry as long as no other values are removed from earlier positions in the list first.
addTaskCallback返回一个整型值,给任务的回调,这一新的回调占地列表中的位置。这仅仅是当前位置的回调。它可以用来清除只要先移除从列表中较早的立场,因为没有其他值的条目。

removeTaskCallback returns a logical value indicating whether the specified element was removed. This can fail (i.e., return FALSE) if an incorrect name or index is given that does not correspond to the name or position of an element in the list.
removeTaskCallback返回一个逻辑值,指示是否被删除指定的元素。这可能会失败(即返回FALSE)如果一个不正确的名称或索引不对应列表中的元素的名称或位置。


注意----------Note----------

There is also C-level access to top-level task callbacks to allow C routines rather than R functions be used.
还有C级的访问顶层的任务回调,让C例程,而不是R函数可用于。


参见----------See Also----------

getTaskCallbackNames taskCallbackManager http://developer.r-project.org/TaskHandlers.pdf
getTaskCallbackNamestaskCallbackManagerhttp://developer.r-project.org/TaskHandlers.pdf


举例----------Examples----------


times <- function(total = 3, str="Task a") {
   ctr <- 0

   function(expr, value, ok, visible) {
    ctr <<- ctr + 1
    cat(str, ctr, "\n")
    if(ctr == total) {
      cat("handler removing itself\n")
    }
    return(ctr < total)
   }
}

# add the callback that will work for[添加回调,将工作]
# 4 top-level tasks and then remove itself.[4个顶层的任务,然后删除自身。]
n <- addTaskCallback(times(4))

# now remove it, assuming it is still first in the list.[现在删除它,假设它仍然是列表中的第一。]
removeTaskCallback(n)

## Not run: [#无法运行:]
# There is no point in running this[有没有在运行此点]
# as [如]
addTaskCallback(times(4))

sum(1:10)
sum(1:10)
sum(1:10)
sum(1:10)
sum(1:10)

## End(Not run)[#结束(不运行)]

转载请注明:出自 生物统计家园网(http://www.biostatistic.net)。


注:
注1:为了方便大家学习,本文档为生物统计家园网机器人LoveR翻译而成,仅供个人R语言学习参考使用,生物统计家园保留版权。
注2:由于是机器人自动翻译,难免有不准确之处,使用时仔细对照中、英文内容进行反复理解,可以帮助R语言的学习。
注3:如遇到不准确之处,请在本贴的后面进行回帖,我们会逐渐进行修订。
回复

使用道具 举报

您需要登录后才可以回帖 登录 | 注册

本版积分规则

手机版|小黑屋|生物统计家园 网站价格

GMT+8, 2025-2-2 16:47 , Processed in 0.022791 second(s), 16 queries .

Powered by Discuz! X3.5

© 2001-2024 Discuz! Team.

快速回复 返回顶部 返回列表