[R] Object validation and formal classes

Torsten Steuernagel Torsten.Steuernagel at gmx.de
Thu Jan 29 21:30:19 CET 2004


I'm using R 1.8.1 (Win32, Linux) and have some difficulties using 
validation functions for S4 classes. The problem is if I specify a 
validation function with setValidity("myclass", validate.myclass) object 
validation is only performed when I create an instance using 
new("myclass"), or when I explicitly call validObject(x) where x is of 
class "myclass", of course. 

According to the reference docs, I would expect that validation always 
takes place implicitly when I manipulate an object of "myclass". This 
especially includes implicit validation if I change slots directly, i.e. 
x at myslot <- 1:50 should call my validation function. Unfortunately, it 
isn't called and instead of raising an error and leaving the object 
unchanged in case validation fails, the object is always changed no 
matter what I assign to the slot.

I'm not sure if I'm missing something here or if I just didn't get the point 
of validation functions, but I believe there must be a way to assure that 
an object is in a consistent state.

Thanks for your help,

Torsten




More information about the R-help mailing list