Learn R Programming

objectProperties (version 0.6.8)

PropertySet-class: PropertySet-class

Description

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.

Usage

setPropertySet(Class, fields=list(), prototype=list(), contains="PropertySet", ...,
    where=topenv(parent.frame()))

Arguments

Class

class name

fields

list of fields

prototype

list of default values, as in setClass.

contains

superclasses, one of which must extend PropertySet

...

additional arguments to setRefClass

where

the environment in which to define the class

Value

setPropertySet: the class generator object

Details

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.

Examples

Run this code
# NOT RUN {
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
# }

Run the code above in your browser using DataLab