R6
class with generic (abstract) functionality for toolset
models, including model attribute get and set methods that resolve attribute scope
(public, active, attached), attribute aliases, attribute
attachment, and error and warning message attributes.
Super class
poems::GenericClass
-> GenericModel
Active bindings
model_attributes
A vector of model attribute names.
attribute_aliases
A list of alternative alias names for model attributes (form:
alias = "attribute"
) to be used with the set and get attributes methods.error_messages
A vector of error messages encountered when setting model attributes.
warning_messages
A vector of warning messages encountered when setting model attributes.
Methods
Method new()
Initialization method sets given attributes individually and/or from a list.
Usage
GenericModel$new(
model_attributes = NULL,
attribute_aliases = NULL,
params = list(),
...
)
Method new_clone()
Creates a new (re-initialized) object of the current (inherited) object class with optionally passed parameters.
Method get_attribute_names()
Returns an array of all attribute names including public and private model attributes, as well as attached attributes, error and warning messages.
Method get_attributes()
Returns a list of values for selected attributes or attribute aliases (when array of parameter names provided) or all attributes (when no params).
Method get_attribute_aliases()
Returns an array of attribute names and aliases for specified or all attributes.
Method set_attributes()
Sets given attributes (optionally via alias names) individually and/or from a list.
Usage
GenericModel$set_attributes(params = list(), ...)
Examples
model1 <- GenericModel$new(
model_attributes = c("a", "b", "c"),
attribute_aliases = list(A = "a"),
params = list(a = 1, b = 2), c = 3
)
# Get/set attributes
model1$get_attribute_names()
#> [1] "a" "b" "c" "error_messages"
#> [5] "warning_messages"
model1$set_attributes(d = 4)
model1$get_attributes()
#> $a
#> [1] 1
#>
#> $b
#> [1] 2
#>
#> $c
#> [1] 3
#>
#> $d
#> [1] 4
#>
model1$get_attribute("A")
#> [1] 1
model1$get_attribute("B")
#> NULL
model1$get_attribute_aliases() # all attribute names
#> [1] "a" "b" "c" "d"
#> [5] "error_messages" "warning_messages" "A"
# New cloning
model2 <- model1$new_clone(e = 5)
model2$get_attributes()
#> $e
#> [1] 5
#>
model2$modelattributes
#> NULL
model2$attribute_aliases
#> $A
#> [1] "a"
#>