| Line 22... |
Line 22... |
| 22 |
\details{
|
22 |
\details{
|
| 23 |
These functions apply only to packages with name spaces.
|
23 |
These functions apply only to packages with name spaces.
|
| 24 |
|
24 |
|
| 25 |
After loading, \code{\link{loadNamespace}} looks for a hook function named
|
25 |
After loading, \code{\link{loadNamespace}} looks for a hook function named
|
| 26 |
\code{.onLoad} and runs it before sealing the namespace and processing
|
26 |
\code{.onLoad} and runs it before sealing the namespace and processing
|
| 27 |
exports. Note that the code is run without the package being on the
|
- |
|
| 28 |
search path, so objects in the package need to be referred to using the
|
- |
|
| 29 |
double colon operator.
|
27 |
exports.
|
| 30 |
|
28 |
|
| 31 |
If a name space is unloaded (via \code{\link{unloadNamespace}}),
|
29 |
If a name space is unloaded (via \code{\link{unloadNamespace}}),
|
| 32 |
a hook function \code{.onUnload} is run before final unloading.
|
30 |
a hook function \code{.onUnload} is run before final unloading.
|
| 33 |
|
31 |
|
| - |
|
32 |
Note that the code in \code{.onLoad} and \code{.onUnload} is run
|
| - |
|
33 |
without the package being on the search path, but (unless circumvented)
|
| - |
|
34 |
lexical scope will make objects in the namespace and its imports
|
| - |
|
35 |
visible. (Do not use the double colon operator in \code{.onLoad} as
|
| - |
|
36 |
exports have not been processed at the point it is run.)
|
| - |
|
37 |
|
| 34 |
When the package is attached (via \code{\link{library}}), the hook
|
38 |
When the package is attached (via \code{\link{library}}), the hook
|
| 35 |
function \code{.onAttach} is called after the exported functions are
|
39 |
function \code{.onAttach} is called after the exported functions are
|
| 36 |
attached. This is less likely to be useful than \code{.onLoad}, which
|
40 |
attached. This is less likely to be useful than \code{.onLoad}, which
|
| 37 |
should be seen as the analogue of \code{\link{.First.lib}} (which is only
|
41 |
should be seen as the analogue of \code{\link{.First.lib}} (which is only
|
| 38 |
used for packages without a name space).
|
42 |
used for packages without a name space).
|
| 39 |
|
43 |
|
| 40 |
\code{.onLoad}, \code{.onUnload} and \code{.onAttach} are looked for
|
44 |
\code{.onLoad}, \code{.onUnload} and \code{.onAttach} are looked for
|
| 41 |
as internal variables in the name space and should not be exported.
|
45 |
as internal variables in the name space and should not be exported.
|
| 42 |
|
46 |
|
| 43 |
A function \code{\link{.Last.lib}} will be called when the package is
|
47 |
If a function \code{\link{.Last.lib}} is visible in the package, it
|
| 44 |
detached: this does need to be exported.
|
48 |
will be called when the package is detached: this does need to be exported.
|
| 45 |
|
49 |
|
| 46 |
Anything needed for the functioning of the name space should be
|
50 |
Anything needed for the functioning of the name space should be
|
| 47 |
handled at load/unload times by the \code{.onLoad} and
|
51 |
handled at load/unload times by the \code{.onLoad} and
|
| 48 |
\code{.onUnload} hooks. For example, shared libraries can be loaded
|
52 |
\code{.onUnload} hooks. For example, shared libraries can be loaded
|
| 49 |
(unless done by a \code{useDynib} directive in the \code{NAMESPACE}
|
53 |
(unless done by a \code{useDynib} directive in the \code{NAMESPACE}
|