Displaying 2 results from an estimated 2 matches for "posnumber".
2005 Aug 03
0
A question on validity checking for S4 classes
...uot;Objects are checked for validity when
permanently assigned, or explicitly by the function validObject()." The Help
for setValidity() seems silent on the details, however, and this does not
appear to be the R implementation. Here's an example to show why I think
not:
> setClass('posNumber','numeric')
[1] "posNumber"
> setValidity('posNumber',function(object)
+ if(any(object at .Data<=0))'Must be positive numbers'
+ else TRUE)
Slots:
Name: .Data
Class: numeric
Extends:
Class "numeric", from data part
Class &q...
2009 Aug 10
1
Validity check when setting slot
Hi,
I'm wondering if the following behaviour is normal:
setClass('A', representation(number='numeric'),
validity=function(object){
if( object at number < -1 ) return("Invalid number"); TRUE})
>[1] "A"
a <- new('A')
a
>An object of class ?A?
>Slot "number":
>numeric(0)
a at number <- 0
a at number <- -3
a
>An