module
to define self contained organizational units. Modules have
their own search path. import
can be used to import packages.
use
can be used to import other modules.
module(expr = { }, topEncl = autoTopEncl(parent.frame()))
"print"(x, ...)
import(from, ..., where = parent.frame())
use(module, ..., attach = FALSE, reInit = TRUE, where = parent.frame())
expose(module, ..., reInit = TRUE, where = parent.frame())
export(..., where = parent.frame())
autoTopEncl(where)
topEncl
is the environment where the search of the module ends.
autoTopEncl
handles the different situations. In general it defaults
to the base environment or the environment from which module
has been
called. If you are using use
or expose
refering to a module in
a file, it will always be the base environment. When
identical(topenv(parent.frame()), globalenv())
is false it (most
likely) means that the module is part of a package. In that case the module
defines a sub unit within a package but has access to the packages namespace.
This is relevant when you use the function module explicitly. When you define
a nested module which the module will connect to the calling environment.import
and use
are no replacements for library and
attach. Both will work when called in the .GlobalEnv
but should
only be used for development and debugging of modules.
export
will never export a function with a leading "." in its name.
expose
is similar to use
but instead of attaching a module it
will copy all elements into the calling environment. This means that all
functions will be re-exported; if not stated otherwise using export
.
## Not run:
# vignette("modulesInR", "modules")
# ## End(Not run)
Run the code above in your browser using DataLab