[R] Validity check when setting slot

Renaud Gaujoux
2009-08-10T15:19:12Z

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 object of class ?A?
>Slot "number":
>[1] -3

So: the slot is set to an invalid value according to the validity method
and nothing happens (no error) whereas the doc says:
"The replacement forms do check (except for
     'slot' in the case 'check=FALSE').  So long as slots are
set
     without cheating, the extracted slots will be valid."

Thanks,
Renaud

> sessionInfo()
R version 2.9.1 (2009-06-26)
i486-pc-linux-gnu

locale:
LC_CTYPE=en_ZA.UTF-8;LC_NUMERIC=C;LC_TIME=en_ZA.UTF-8;LC_COLLATE=en_ZA.UTF-8;LC_MONETARY=C;LC_MESSAGES=en_ZA.UTF-8;LC_PAPER=en_ZA.UTF-8;LC_NAME=C;LC_ADDRESS=C;LC_TELEPHONE=C;LC_MEASUREMENT=en_ZA.UTF-8;LC_IDENTIFICATION=C

attached base packages:
[1] stats     graphics  grDevices utils     datasets  methods   base