[Bioc-devel] S4 validity checking {was "eset.Rnw revised in Biobase"}

Martin Maechler maechler at stat.math.ethz.ch
Tue Sep 6 09:56:23 CEST 2005


>>>>> "Kasper" == Kasper Daniel Hansen <khansen at stat.berkeley.edu>
>>>>>     on Mon, 5 Sep 2005 15:45:30 -0700 writes:

   .................

    Kasper> 7) So the assayData slot does not have a specific
    Kasper> number/names for its components. I see the need for
    Kasper> this. But let us say I want to use it for a specific
    Kasper> case where I have two assays (let us say a two-
    Kasper> color micro array experiment). Do you imagine that
    Kasper> people will create more specific versions of the
    Kasper> class by something like (code not tested)

(yes, it was missing 3 closing ")" 
  --- quickly seen when using Emacs with "paren match" activated)

    >>    setClass("twoclor", representation("eSet"),
    >>       validity = function(object){
    >>          if(!validObject(as(object, "eSet")))
    >>             return(FALSE)  ## this might be unnecessary
    >>          if(sort(names(assayData(object)) != c("green", "red")))
    >>             return(FALSE)
    >>          else
    >>            return(TRUE)
    >>        })

I want to comment on the above code, since
I think I've seen the same mistake several times in people's code:

Validity checking should  **NOT** return TRUE or FALSE,
but  TRUE or <reason for non-validity> .
This has been in `The Green Book' but also the very first entry in
   ?SetValidity
or ?validObject :

>> Description:
>> 
>>      The validity of 'object' related to its class definition is
>>      tested.  If the object is valid, 'TRUE' is returned; otherwise,
>>      either a vector of strings describing validity failures is
>>      returned, or an error is generated (according to whether 'test' is
>>      'TRUE').
>> 
>>      The function 'setValidity' sets the validity method of a class
>>      (but more normally, this method will be supplied as the 'validity'
>>      argument to 'setClass').  The method should be a function of one
>>      object that returns 'TRUE' or a description of the non-validity.

Martin



More information about the Bioc-devel mailing list