import and use
can replace library and attach.
However they behave differently and are only designed to be used within
modules. Both will work when called in the .GlobalEnv
but here they
should only be used for development and debugging of modules.
use
adds a layer to a local search path if attach
is
TRUE
. More precisely to the calling environment, which is the
environment supplied by where
. Regardless of the attach
argument, use
will return the module invisibly.
use
supplies a special mechanism to find the argument module
:
generally you can supply a file name or folder name as character. You can
also reference objects/names which 'live' outside the module scope. If
names are not found within the scope of the module, they are searched for
in the environment in which the module has been defined. This happens
during initialization of the module, when the use
function is
called.
Modules can live in files. use
should be used to load them. A module
definition in a file does not need to use the module constructor
explicitly. Any R script can be used as the body of a module.
When a folder is referenced in use
it is transformed into a list of
modules. This is represented as a nested list mimicking the folder
structure. Each file in that folder becomes a module.