callHooks | R Documentation |
Call hook functions by hook name.
## Default S3 method:
callHooks(hookName, ..., removeCalledHooks=FALSE)
hookName |
A |
... |
Argument passed to each hook function. |
removeCalledHooks |
If |
Returns (invisibly) whatever callHooks.list
() returns.
Henrik Bengtsson
Internally, after retrieving hook functions, callHooks.list
() is
called.
# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
# Example 1
# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
# First, clean up if called more than once
setHook("myFunction.onEnter", NULL, action="replace")
setHook("myFunction.onExit", NULL, action="replace")
runConference <- function(...) {
callHooks("myFunction.onEnter")
cat("Speaker A: Hello there...\n")
callHooks("myFunction.onExit")
}
setHook("myFunction.onEnter", function(...) {
cat("Chair: Welcome to our conference.\n")
})
setHook("myFunction.onEnter", function(...) {
cat("Chair: Please welcome Speaker A!\n")
})
setHook("myFunction.onExit", function(...) {
cat("Chair: Please thanks Speaker A!\n")
})
runConference()
# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
# Example 2
# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
setHook("randomNumber", NULL, action="replace")
setHook("randomNumber", rnorm) # By function
setHook("randomNumber", "rexp") # By name
setHook("randomNumber", "runiff") # Non-existing name
setHook("randomNumber", .GlobalEnv) # Not a function
res <- callHooks("randomNumber", n=1)
str(res)
cat("Number of hooks: ", length(res), "\n")
isErroneous <- unlist(lapply(res, FUN=function(x) !is.null(x$exception)))
cat("Erroneous hooks: ", sum(isErroneous), "\n")
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.