PropertySet-class | R Documentation |
The PropertySet
class is a collection of properties and is
useful as a data model, e.g., for storing the parameters of some
operation.
setPropertySet
is a simple wrapper around setRefClass
for
creating subclasses of PropertySet
. It
ensures that all fields of the subclass are defined via
properties
.
setPropertySet(Class, fields=list(), prototype=list(), contains="PropertySet", ..., where=topenv(parent.frame()))
Class |
class name |
fields |
list of fields |
prototype |
list of default values, as in
|
contains |
superclasses, one of which must extend PropertySet |
... |
additional arguments to |
where |
the environment in which to define the class |
PropertySet-class
: PropertySet
object has following methods, where x
is
a PropertySet
object:
x$properties()
Return the classes of the properties as a
named character vector. Compare to the fields
method on
a reference class generator
.
as.list(x)
Returns a named list of the property values.
When any property in the set changes, the changed(name)
signal is emitted, where name
is the name of the property
that changed.
setPropertySet
: the class generator object
Michael Lawrence, Tengfei Yin
filt.gen <- setRefClass("Filter", properties(fields = list(cutoff = "numeric", weight = "numeric"), prototype = list(cutoff = 0, weight = 1)), contains = "PropertySet") obj <- filt.gen$new() obj obj$properties() as.list(obj) obj$changed$connect(function(name) print(name)) obj$cutoffChanged$connect(function() print(paste("change to", obj$cutoff))) obj$cutoff <- 0 obj$cutoff <- 2 obj$weight <- 3 ## use setPropertySet, the same thing as above filt.gen <- setPropertySet("Filter", fields = list(cutoff = "numeric", weight = "numeric"), prototype = list(cutoff = 0, weight = 1)) obj <- filt.gen$new() obj obj$properties() as.list(obj) obj$changed$connect(function(name) print(name)) obj$cutoffChanged$connect(function() print(paste("change to", obj$cutoff))) obj$cutoff <- 0 obj$cutoff <- 2 obj$weight <- 3
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.