validObject(object, test=FALSE)
test=F
, it throws an error if the validity checker did not return
TRUE
, and returns the object otherwise. If
test=T
, it returns the output of the validity checker.
TRUE
, and returns the object otherwise. If
test=T
, it returns the output of the validity checker.
The validity checker is the function given as the
validity
argument to
setClass
when the class is defined. This can be seen by running
getClass(myclass)@validity
and changed with
setValidity
.
# Create an object and test to see if it is a valid object setClass("qaz", where=0, rep=representation(x="numeric",n="integer"), validity=function(object) {if(length(object@x)!=object@n)"length(object@x) !=object@n" else TRUE}) qaz <- function(x) { obj <- new("qaz") obj@x <- x ; obj@n <- length(x) obj } z<-qaz(56:58) z@n<-10 validObject(z) # test=F validObject(z, test=F) Problem in validObject(z, test = F): invalid object: : length(object@x)!=object@n Use traceback() to see the call stack # test=T validObject(z, test=T) [1] ": length(object@x)!=object@n"