I'm looking for a method to validate S3 objects in my package Momocs.
Earlier versions of the package were written using S4, then I shifted back to S3 for the sake of flexibility, because users were more into S3, because I do not really need multiple inheritance, etc.. The main cost of this change was actually losing S4 representation / validity checking.
My problem follows: how can we prevent one from inadvertently "unvalidate" an S3 object, for instance trying to extend existing methods or manipulating object structure?
I have already written some validate
function but, so far, I only validate before crucial steps, typically those turning an object from a class into another.
My question is:
- do I want to have my cake and eat it (S3 flexibility and S4 representation checking) ? In that case, I would need to add my
validate
function across all the methods of my package? - or is there a smarter way on top of S3, something like "any time we do something on an object of a particular class, call a
validate
function on it"?