Learn R Programming

objectProperties (version 0.6.8)

setNumericWithRange: Define a speicific range object

Description

This class creator is used to define a special property for numeric range, which could be used for UI design and could be setted as signaling field, so it will support validation on the input.

Usage

setNumericWithRange(prefix = "Numeric", min, max, where=topenv(parent.frame()))

Arguments

prefix

Prefix for new class name.Default is "Numeric"

min

Minimal value for this range object.

max

Maximal value for this range object.

where

the environment in which to store or remove the definition. Defaults to the top-level environment of the calling function.

Value

A S4 class name in R(< 2.15) and a generator function in R(>= 2.15)

Details

The purpose of creating such a class genenrator is to define a special range properties which could be set as singaling field, such as Properties object. Then validation will be turned on automatically to make sure the current value is within the defined range. This is particular useful when you try to design a slider widget of such a property, let's say, a alpha blending slider.

Examples

Run this code
# NOT RUN {
num1to100.gen <- setNumericWithRange(min = 1, max = 100)
par.gen <- setRefClass("Graph",
                       properties(list(size = "NumericWithMin1Max100")))
pars <- par.gen$new(size = new("NumericWithMin1Max100", 5))
pars$size #current value is 5
try(pars$size <- 300) # out of range error
pars$size <- 10 #works

## Positive Integer
par.gen <- setRefClass("PI", properties(list(size  = "PositiveInteger"),
                                        list(size = PositiveInteger(2))))
obj <- par.gen$new()
## error
try(obj$size <- -1)
obj$size <- 3
# }

Run the code above in your browser using DataLab