Hi,

It would be nice if there was a tool for checking the validity of any
object. validObject() is of course the natural candidate for this but
right now it doesn't work on S3 objects:

  df <- data.frame(aa=1:4, bb=letters[4:1])
  attributes(df)$row.names <- c("A", "B", "C", "A")

'df' is an invalid data frame instance:

  > df
  Error in data.frame(aa = c("1", "2", "3", "4"), bb = c("d", "c", "b",  :
    duplicate row.names: A

However:

  > validObject(df)
  [1] TRUE
  > validObject(df, complete=TRUE)
  [1] TRUE

Also, here is another (typical) situation where it would be nice to be
able to (recursively) check the validity of the object:

  setClass("Collection", representation(things="list"))
  mycollection <- new("Collection", things=list(object1, object2, object3))

The problem is that 'validObject(mycollection, complete=TRUE)'
will return TRUE, even if one of the 3 objects stored in 'mycollection'
is invalid. I could implement my own validity method for Collection
objects but that's not a satisfactory solution because it would always
do a deep check (validity methods don't handle the 'complete' argument).

Would it make sense to modify validObject() so that, when called with
'complete=TRUE', it recursively validates the components of a list or
environment?

Thanks,
H.

--
Hervé Pagès

Program in Computational Biology
Division of Public Health Sciences
Fred Hutchinson Cancer Research Center
1100 Fairview Ave. N, M1-B514
P.O. Box 19024
Seattle, WA 98109-1024

E-mail: hpa...@fhcrc.org
Phone:  (206) 667-5791
Fax:    (206) 667-1319

______________________________________________
R-devel@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/r-devel

Reply via email to