Movatterモバイル変換


[0]ホーム

URL:


rdrr.io

taskCallback: Add or Remove a Top-Level Task Callback

taskCallbackR Documentation

Add or Remove a Top-Level Task Callback

Description

addTaskCallback registers an R functionthat is to be called each time a top-level taskis completed.

removeTaskCallback un-registers a functionthat was registered earlier viaaddTaskCallback.

These provide low-level access to the internal/nativemechanism for managing task-completion actions.One can usetaskCallbackManagerat theR-language level to manageR functionsthat are called at the completion of each task.This is easier and more direct.

Usage

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

Arguments

f

the function that is to be invoked each time a top-level taskis successfully completed. This is called with 5 or 4 argumentsdepending on whetherdata is specified or not, respectively.The return value should be a logical value indicating whether tokeep the callback in the list of active callbacks or discard it.

data

if specified, this is the 5-th argument in the call to thecallback functionf.

id

a string or an integer identifying the element in theinternal callback list to be removed.Integer indices are 1-based, i.e the first element is 1.The names of currently registered handlers is availableusinggetTaskCallbackNamesand is also returned in a call toaddTaskCallback.

name

character: names to be used.

Details

Top-level tasks are individual expressionsrather than entire lines of input. Thus an inputline of the formexpression1 ; expression2will give rise to 2 top-level tasks.

A top-level task callback is called with the expression for thetop-level task, the result of the top-level task, a logical valueindicating whether it was successfully completed or not (always TRUEat present), and a logical value indicating whether the result wasprinted or not. If thedata argument was specified in the calltoaddTaskCallback, that value is given as the fifth argument.

The callback function should return a logical value.If the value is FALSE, the callback is removed from the tasklist and will not be called again by this mechanism.If the function returns TRUE, it is kept in the list andwill be called on the completion of the next top-level task.

Value

addTaskCallback returnsan integer value giving the position in the listof 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 asno other values are removed from earlier positionsin the list first.

removeTaskCallback returns a logical valueindicating whether the specified element was removed.This can fail (i.e., returnFALSE)if an incorrect name or index is given that does notcorrespond to the name or position of an element in the list.

Note

There is also C-level access to top-level task callbacksto allow C routines rather than R functions be used.

See Also

getTaskCallbackNamestaskCallbackManagerhttps://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")    keep.me <- (ctr < total)    if (!keep.me)      cat("handler removing itself\n")    # return    keep.me  }}# add the callback that will work for# 4 top-level tasks and then remove itself.n <- addTaskCallback(times(4))# now remove it, assuming it is still first in the list.removeTaskCallback(n)## See how the handler is called every time till "self destruction":addTaskCallback(times(4)) # counts as once alreadysum(1:10) ; mean(1:3) # two moresinpi(1)              # 4th - and "done"cospi(1)tanpi(1)

What can we improve?

R Package Documentation

Browse R Packages

We want your feedback!

Note that we can't provide technical support on individual packages. You should contact the package authors for that.

 
Embedding an R snippet on your website

Add the following code to your website.

For more information on customizing the embed code, readEmbedding Snippets.

Close

[8]ページ先頭

©2009-2026 Movatter.jp