Modules can declare functions to be called when a module is first loaded.
.on_load(ns).on_unload(ns)
the module namespace environment
.on_load
is called for its side-effect. Any return value is
ignored.
To create module hooks, modules should define a function with the specified name and signature. Module hooks should not be exported.
When .on_load
is called, the unlocked module namespace environment is
passed to it via its parameter ns
. This means that code in
.on_load
is permitted to modify the namespace by adding names to,
replacing names in, or removing names from the namespace.
.on_unload
is called when modules are unloaded. The (locked) module
namespace is passed as an argument. It is primarily useful to clean up
resources used by the module. Note that, as for packages, .on_unload
is not necessarily called when R is shut down.