The functions loadNamespace
and attachNamespace
are
usually called implicitly when library
is used to load a name
space and any imports needed. However it may be useful at times to
call these functions directly. loadNamespace
loads the specified name space and registers it in
an internal data base. A request to load a name space when one of that
name is already loaded has no effect. The arguments have the same
meaning as the corresponding arguments to library
, whose
help page explains the details of how a particular installed package
comes to be chosen. After loading, loadNamespace
looks for a
hook function named .onLoad
as an internal variable in
the name space (it should not be exported). Partial loading is used
to support installation with lazy-loading.
loadNamespace
does not attach the name space it loads to the
search path. attachNamespace
can be used to attach a frame
containing the exported values of a name space to the search path (but
this is almost always done via library
). The
hook function .onAttach
is run after the name space
exports are attached.
requireNamespace
is a wrapper for loadNamespace
analogous to require
that returns a logical value.
loadedNamespaces
returns a character vector of the names of
the loaded name spaces.
isNamespaceLoaded(pkg)
is equivalent to but more efficient than
pkg %in% loadedNamespaces()
.
unloadNamespace
can be used to attempt to force a name space to
be unloaded. If the name space is attached, it is first
detach
ed, thereby running a .onDetach
or
.Last.lib
function in the name space if one is exported. An
error is signaled and the name space is not unloaded if the name space
is imported by other loaded name spaces. If defined, a hook function
.onUnload
is run before removing the name space from the
internal registry.
See the comments in the help for detach
about some
issues with unloading and reloading name spaces.