When I was introducing the special type for S4 objects, my first inclination was to have length(x) for those objects be either NA or an error, along the lines that intuitively length(x) means "the number of elements in the vector-style object x". However, that change quickly was demonstrated to need MANY revisions to the current code.
As a compromise, my preference would be that S4 objects have length 0. That was true before the S4 type was introduced, and if memory serves, that was what we expected in early S for objects that were not vectors. Maybe we can try that out, at least for 2.4.1. But as often happens, we have to deal with the fact that R has many authors. That's usually a good thing, but it does mean that different corners of the code will be locally sensible, but not globally consistent. (Having just spent the best part of a day "debugging" a problem that turned out to be the result of an S3 method for trunc() in base that ignored the documented number of arguments, the inconsistencies are on my mind at the moment.) Martin Maechler wrote: >>>>>> "Seth" == Seth Falcon <[EMAIL PROTECTED]> >>>>>> on Fri, 18 Aug 2006 09:54:54 -0700 writes: >>>>>> > > Seth> Martin Maechler <[EMAIL PROTECTED]> writes: > >> I agree you've found an "infelicity" in the current setup, > >> since > >> > >> > setClass("A", representation(x="numeric")) > >> [1] "A" > >> > getClass("A")@prototype > >> <S4 Type Object> > >> attr(,"x") > >> numeric(0) > >> > length(getClass("A")@prototype) > >> [1] 1 > >> > getClass("A")@prototype[1] > >> Error in getClass("A")@prototype[1] : object is not subsettable > >> > > >> > >> It's not clear yet to me *what* should be changed. > >> For my taste, if length(object) returns 1, > >> I'd typically want that object[1] should be valid; > >> but I think we already have some (peculiar) exceptions to that > >> rule. > > Seth> I disagree with the notion that length and "[" should be tightly > Seth> coupled. An object having length doesn't have to mean that > subsetting > Seth> makes any sense. For example, an environment has length, but what > Seth> should env1[1] return? And with S4 classes, there are many such > Seth> examples where "[i]" won't make sense. > > You are right. I was rather thinking of "basic" objects > rather than highly structured objects such as S4 classes. > > Note that for me, an environment belongs into the > category of "peculiar" exceptions ;-) > > Martin > > Seth> + seth > > ______________________________________________ > R-devel@r-project.org mailing list > https://stat.ethz.ch/mailman/listinfo/r-devel > > [[alternative HTML version deleted]] ______________________________________________ R-devel@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-devel