userhooks
Functions to Get and Set Hooks for Load, Attach, Detach and Unload

Description

Gets or sets hooks for a package or a namespace for the events load, attach, detach and unload.

Usage

getHook(hookName)
setHook(hookName, value, action = c("append", "prepend", "replace"))
packageEvent(pkgname, event = c("onLoad", "attach", 
     "detach", "onUnload"))

Arguments

hookName a character string specifying the hook name. Usually, it is the result returned by packageEvent.
value a hook function or NULL.
action a character string specifying the action. Must be one of "append", "prepend", or "replace". Partial matching is accepted.
pkgname a character string specifying the name of package or namespace associated with given event.
event a character string specifying the event that a package or a namespace associates. Must be one of "onLoad", "attach", "detach" or "onUnload". Partial matching is accepted.

Details

A hook can be set to a package or a namespace as an additional capability to allow an end user to customize an operation while the specified package or namespace is loaded, attached, detached or unloaded. A new hook can be appended or prepended to an existing hook, or it can replace an existing hook. (To replace an existing hook, set a hook with NULL value in the "replace" action.)
A hook name is generated by packageEvent with the following format:
UserHook::package_name::event
package_name is a simple string specifying the package name. If the package name contains "_" symbols, only the character string preceding the "_" is used in hook name. See Examples.
All hooks are stored in the environment using the global variable .userHooksEnv, which is dedicated for hooks. This environment is maintained internally by system.
Value
getHookreturns a function or a list of functions of the hook specified by hookName, or it returns an empty list if the hook does not exist.
setHookreturns nothing.
packageEventreturns a character string representing the hook name.
See Also
library, attach, assign
Examples
packageEvent("package1_test_abc", "onLoad")  # "UserHook::package1::onLoad"
packageEvent("package2.test.abc", "at") # "UserHook::package2.test.abc::attach"

setHook(packageEvent("ff", "onLoad"), function(...) base::options(ffbatchbytes = 16095641, ffmaxbytes = 804782080)) # set a new hook getHook(packageEvent("ff", "onLoad"))

setHook(packageEvent("ff", "onLoad"), function(...) base::options(ff_foo = TRUE), action = "prepend") # prepend a hook to above one. getHook(packageEvent("ff", "onLoad"))

setHook(packageEvent("ff", "onLoad"), NULL, action = "replace") # remove the hook getHook(packageEvent("ff", "onLoad"))

Package base version 6.1.1-7
Package Index