getHook(hookName) setHook(hookName, value, action = c("append", "prepend", "replace"))
packageEvent(pkgname, event = c("onLoad", "attach", "detach", "onUnload"))
action = "replace",
getHookfunction, a list of functions (possibly empty). For
setHookfunction, no return value. For
packageEvent, the derived hook name (a character string).
setHookprovides a general mechanism for users to register hooks, a list of functions to be called from system (or user) functions. The initial set of hooks was associated with events on packages/namespaces: these hooks are named via calls to
packageEvent. To remove a hook completely, call
setHook(hookName, NULL, "replace"). When an R package is attached by
libraryor loaded by other means, it can call initialization code. See
.onLoadfor a description of the package hook functions called during initialization. Users can add their own initialization code via the hooks provided by
setHook(), functions which will be called as
funname(pkgname, pkgpath)inside a
trycall. The sequence of events depends on which hooks are defined, and whether a package is attached or just loaded. In the case where all hooks are defined and a package is attached, the order of initialization events is as follows:
.onLoadfunction is run.
"onLoad"hook is run.
.onAttachfunction is run.
"attach"hook is run.
"detach"hook is run.
.Last.libfunction is run.
"onUnload"hook is run.
.onUnloadfunction is run.
getHook, but the
"onUnload"hooks are run in reverse order so the default for package events is to add hooks ‘inside’ existing ones. The hooks are stored in the environment
.userHooksEnvin the base package, with ‘mangled’ names.
::for a discussion of the double and triple colon operators. Other hooks may be added later: functions
perspalready have them.