| Line 2... |
Line 2... |
| 2 |
% Part of the R package, http://www.R-project.org
|
2 |
% Part of the R package, http://www.R-project.org
|
| 3 |
% Copyright 1995-2012 R Core Team
|
3 |
% Copyright 1995-2012 R Core Team
|
| 4 |
% Distributed under GPL 2 or later
|
4 |
% Distributed under GPL 2 or later
|
| 5 |
|
5 |
|
| 6 |
\name{ns-load}
|
6 |
\name{ns-load}
|
| 7 |
\title{Loading and Unloading Namespaces}
|
7 |
\title{Loading and Unloading Name Spaces}
|
| 8 |
|
8 |
|
| 9 |
\alias{attachNamespace}
|
9 |
\alias{attachNamespace}
|
| 10 |
\alias{loadNamespace}
|
10 |
\alias{loadNamespace}
|
| 11 |
\alias{requireNamespace}
|
11 |
\alias{requireNamespace}
|
| 12 |
\alias{loadedNamespaces}
|
12 |
\alias{loadedNamespaces}
|
| 13 |
\alias{unloadNamespace}
|
13 |
\alias{unloadNamespace}
|
| 14 |
|
14 |
|
| 15 |
\description{
|
15 |
\description{
|
| 16 |
Functions to load and unload namespaces.
|
16 |
Functions to load and unload name spaces.
|
| 17 |
}
|
17 |
}
|
| 18 |
\usage{
|
18 |
\usage{
|
| 19 |
attachNamespace(ns, pos = 2, dataPath = NULL, depends = NULL)
|
19 |
attachNamespace(ns, pos = 2L, depends = NULL)
|
| 20 |
loadNamespace(package, lib.loc = NULL,
|
20 |
loadNamespace(package, lib.loc = NULL,
|
| 21 |
keep.source = getOption("keep.source.pkgs"),
|
21 |
keep.source = getOption("keep.source.pkgs"),
|
| 22 |
partial = FALSE, versionCheck = NULL)
|
22 |
partial = FALSE, versionCheck = NULL)
|
| 23 |
requireNamespace(package, ..., quietly = FALSE)
|
23 |
requireNamespace(package, ..., quietly = FALSE)
|
| 24 |
loadedNamespaces()
|
24 |
loadedNamespaces()
|
| 25 |
unloadNamespace(ns)
|
25 |
unloadNamespace(ns)
|
| 26 |
}
|
26 |
}
|
| 27 |
\arguments{
|
27 |
\arguments{
|
| 28 |
\item{ns}{string or namespace object.}
|
28 |
\item{ns}{string or name space object.}
|
| 29 |
\item{pos}{integer specifying position to attach.}
|
29 |
\item{pos}{integer specifying position to attach.}
|
| 30 |
\item{dataPath}{path to directory containing a database of datasets to
|
- |
|
| 31 |
be lazy-loaded into the attached environment.}
|
- |
|
| 32 |
\item{depends}{\code{NULL} or a character vector of dependencies to be
|
30 |
\item{depends}{\code{NULL} or a character vector of dependencies to be
|
| 33 |
recorded in object \code{.Depends} in the package.}
|
31 |
recorded in object \code{.Depends} in the package.}
|
| 34 |
\item{package}{string naming the package/namespace to load.}
|
32 |
\item{package}{string naming the package/name space to load.}
|
| 35 |
\item{lib.loc}{character vector specifying library search path.}
|
33 |
\item{lib.loc}{character vector specifying library search path.}
|
| 36 |
\item{keep.source}{Now ignored except during package installation.
|
34 |
\item{keep.source}{Now ignored except during package installation.
|
| 37 |
For more details see this argument to \code{\link{library}}.
|
35 |
For more details see this argument to \code{\link{library}}.
|
| 38 |
}
|
36 |
}
|
| 39 |
\item{partial}{logical; if true, stop just after loading code.}
|
37 |
\item{partial}{logical; if true, stop just after loading code.}
|
| Line 43... |
Line 41... |
| 43 |
\item{\dots}{further arguments to be passed to \code{loadNamespace}.}
|
41 |
\item{\dots}{further arguments to be passed to \code{loadNamespace}.}
|
| 44 |
}
|
42 |
}
|
| 45 |
\details{
|
43 |
\details{
|
| 46 |
The functions \code{loadNamespace} and \code{attachNamespace} are
|
44 |
The functions \code{loadNamespace} and \code{attachNamespace} are
|
| 47 |
usually called implicitly when \code{library} is used to load a name
|
45 |
usually called implicitly when \code{library} is used to load a name
|
| 48 |
space and any imports needed. However it may be useful to call
|
46 |
space and any imports needed. However it may be useful at times to
|
| 49 |
these functions directly at times.
|
47 |
call these functions directly.
|
| 50 |
|
48 |
|
| 51 |
\code{loadNamespace} loads the specified namespace and registers it in
|
49 |
\code{loadNamespace} loads the specified name space and registers it in
|
| 52 |
an internal data base. A request to load a namespace when one of that
|
50 |
an internal data base. A request to load a name space when one of that
|
| 53 |
name is already loaded has no effect. The arguments have the same
|
51 |
name is already loaded has no effect. The arguments have the same
|
| 54 |
meaning as the corresponding arguments to \code{\link{library}}, whose
|
52 |
meaning as the corresponding arguments to \code{\link{library}}, whose
|
| 55 |
help page explains the details of how a particular installed package
|
53 |
help page explains the details of how a particular installed package
|
| 56 |
comes to be chosen. After loading, \code{loadNamespace} looks for a
|
54 |
comes to be chosen. After loading, \code{loadNamespace} looks for a
|
| 57 |
hook function named \code{\link{.onLoad}} as an internal variable in
|
55 |
hook function named \code{\link{.onLoad}} as an internal variable in
|
| 58 |
the namespace (it should not be exported). Partial loading is used
|
56 |
the name space (it should not be exported). Partial loading is used
|
| 59 |
to support installation with lazy-loading.
|
57 |
to support installation with lazy-loading.
|
| 60 |
|
58 |
|
| 61 |
\code{loadNamespace} does not attach the namespace it loads to the
|
59 |
\code{loadNamespace} does not attach the name space it loads to the
|
| 62 |
search path. \code{attachNamespace} can be used to attach a frame
|
60 |
search path. \code{attachNamespace} can be used to attach a frame
|
| 63 |
containing the exported values of a namespace to the search path (but
|
61 |
containing the exported values of a name space to the search path (but
|
| 64 |
this is almost always done \emph{via} \code{\link{library}}). The
|
62 |
this is almost always done \emph{via} \code{\link{library}}). The
|
| 65 |
hook function \code{\link{.onAttach}} is run after the namespace
|
63 |
hook function \code{\link{.onAttach}} is run after the name space
|
| 66 |
exports are attached.
|
64 |
exports are attached.
|
| 67 |
|
65 |
|
| 68 |
\code{requireNamespace} is a wrapper for \code{loadNamespace}
|
66 |
\code{requireNamespace} is a wrapper for \code{loadNamespace}
|
| 69 |
analogous to \code{\link{require}} that returns a logical value.
|
67 |
analogous to \code{\link{require}} that returns a logical value.
|
| 70 |
|
68 |
|
| 71 |
\code{loadedNamespaces} returns a character vector of the names of
|
69 |
\code{loadedNamespaces} returns a character vector of the names of
|
| 72 |
the loaded namespaces.
|
70 |
the loaded name spaces.
|
| 73 |
|
71 |
|
| 74 |
\code{unloadNamespace} can be used to attempt to force a namespace to
|
72 |
\code{unloadNamespace} can be used to attempt to force a name space to
|
| 75 |
be unloaded. If the namespace is attached, it is first
|
73 |
be unloaded. If the name space is attached, it is first
|
| 76 |
\code{\link{detach}}ed, thereby running a \code{.Last.lib} function
|
74 |
\code{\link{detach}}ed, thereby running a \code{\link{.onDetach}} or
|
| 77 |
in the namespace if one is exported. Then an error is signaled if the
|
75 |
\code{.Last.lib} function in the name space if one is exported. An
|
| 78 |
namespace is imported by other loaded namespaces, and the namespace
|
76 |
error is signaled and the name space is not unloaded if the name space
|
| 79 |
is not unloaded. If defined, a hook function \code{\link{.onUnload}}
|
77 |
is imported by other loaded name spaces. If defined, a hook function
|
| 80 |
is run before removing the namespace from the internal registry.
|
78 |
\code{\link{.onUnload}} is run before removing the name space from the
|
| - |
|
79 |
internal registry.
|
| 81 |
|
80 |
|
| 82 |
See the comments in the help for \code{\link{detach}} about some
|
81 |
See the comments in the help for \code{\link{detach}} about some
|
| 83 |
issues with unloading and reloading namespaces.
|
82 |
issues with unloading and reloading name spaces.
|
| 84 |
}
|
83 |
}
|
| 85 |
\value{
|
84 |
\value{
|
| 86 |
\code{attachNamespace} returns invisibly the package environment it
|
85 |
\code{attachNamespace} returns invisibly the package environment it
|
| 87 |
adds to the search path.
|
86 |
adds to the search path.
|
| 88 |
|
87 |
|
| 89 |
\code{loadNamespace} returns the namespace environment, either one
|
88 |
\code{loadNamespace} returns the name space environment, either one
|
| 90 |
already loaded or the one the function causes to be loaded.
|
89 |
already loaded or the one the function causes to be loaded.
|
| 91 |
|
90 |
|
| 92 |
\code{requireNamespace} returns \code{TRUE} if it succeeds or
|
91 |
\code{requireNamespace} returns \code{TRUE} if it succeeds or
|
| 93 |
\code{FALSE}.
|
92 |
\code{FALSE}.
|
| 94 |
|
93 |
|