[Rd] str and s3 classes

Hadley Wickham h.wickham at gmail.com
Wed Jun 19 22:44:05 CEST 2013

Hi all,

Because str uses the generic version of length and names, it's
currently very easy to create objects that break str:

a <- structure(list(1:5), class = "a")
length.a <- function(x) 2L


b <- structure(list(1:5), class = "b")
names.b <- function(x) character()


These are obvious toy examples, but it is a real problem if you want
to create a class that defines names or length in a meaningful way,
that is incompatible with the underlying data structure.


Chief Scientist, RStudio

More information about the R-devel mailing list