setNumericWithRange: Define a speicific range object

Description Usage Arguments Details Value Author(s) Examples

View source: R/comp-classes.R

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

1
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.

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.

Value

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

Author(s)

Tengfei Yin

Examples

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
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

ggobi/objectProperties documentation built on July 20, 2021, 2:21 p.m.