The DiseasyBaseModule
module implements common functionality that all modules have available.
Most notably, the base module facilitates:
logging: A
lgr
logger is configured when making any module that inherits from the base module. This logger is stored inprivate$lg
.hashing: The active binding
self$hash
hashes the values of public fields to provide a way to uniquely identify the configuration of modules. Care must be taken to ensure that information that makes modules distinct are also stored in public fields. That is, if an important property is stored only as a private field, the hash will not change. Module-specific tests should be written to ensure hash changes as expected.caching: The methods
private$cache()
,private$get_hash()
private$is_cached(hash)
implements a simple caching system whereby the results of method calls can be cached to improve the performance of the modules.module loading: Modules instances are sometimes loaded into other modules. The
private$load_module(module)
method provides the functionality to handle this loading (including cloning of the module and passing of the new module to already-loaded modules)
Active bindings
hash
(
character
)
Computes a hash value for the module. Useful for logging and caching. Read only.
Methods
Method new()
Creates a new instance of the DiseasyBaseModule
R6 class.
This module is typically not constructed directly but rather through derived classes.
Usage
DiseasyBaseModule$new(
moduleowner = class(self)[1],
logging = diseasyoption("logging", self)
)
Method load_module()
Loads a copy of the provided module into the module.
Arguments
module
(
R6::R6Class instance
)
This instance is cloned to the field with the same name as the class of the moduleclone
(
boolean
)
Toggle whether or not the module should be cloned when loading. Default TRUE.
Examples
# Normally, you would not want to create this module directly, but it is possible.
base_module <- DiseasyBaseModule$new()
rm(base_module)