[Rd] validObject does not check validity of slots

Martin Morgan mtmorgan at fhcrc.org
Mon Mar 6 17:57:41 CET 2006


The documentation for validObject suggests that slots are checked for
validity, but validObject seems only to check that the slot has
something claiming to be correct; validObject(obj) does not perform
the equivalent of validObject(obj at y) for slot y.

This is also the second problem issue reported in

http://tolstoy.newcastle.edu.au/R/devel/05/03/0151.html

Relevant documentation, an example, and sessionInfo follow.

Martin

validObject             package:methods             R Documentation

Arguments:
     ...
     Note that validity methods do not have to check validity of any
     slots or superclasses:  the logic of 'validObject' ensures these
     tests are done once only.
     ...
Details:

     Validity testing takes place "bottom up":  first the validity of
     the object's slots, if any, is tested.  
     ...

setClass("foo",
         representation( x="numeric" ),
         validity = function( object ) object at x > 0 )
setClass("bar",
         representation( y="foo", z="numeric" ),
         validity = function( object ) object at z > 0 )
obj <- new( "bar", y = new( "foo", x=1 ), z = 1 )

and then...

> validObject( obj )
[1] TRUE
## invalidate obj at y
> obj at y@x <- -1
> validObject( obj at y )                  # right, this is not valid
Error in validObject(obj at y) : invalid class "foo" object: FALSE
> ## obj at y is invalid, but obj is valid?
> validObject( obj )                    # should be invalid?
[1] TRUE



> sessionInfo()
Version 2.3.0 Under development (unstable) (2006-03-03 r37471) 
x86_64-unknown-linux-gnu 

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



More information about the R-devel mailing list