From h.wickham at gmail.com  Wed Jun 19 22:44:05 2013
From: h.wickham at gmail.com (Hadley Wickham)
Date: Wed, 19 Jun 2013 15:44:05 -0500
Subject: [Rd] str and s3 classes
Message-ID: <CABdHhvH08vczUYU=gkcg4-BHypugmtP7GvgfNgWt5YPmXK0quA@mail.gmail.com>

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

str(a)

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

str(b)


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.

Hadley

--
Chief Scientist, RStudio
http://had.co.nz/



[Rd] str and s3 classes
Hadley Wickham