[Rd] S4 'object is not subsettable' in prototype

Prof Brian Ripley ripley at stats.ox.ac.uk
Mon Aug 21 17:10:42 CEST 2006


On Mon, 21 Aug 2006, Seth Falcon wrote:

> John Chambers <jmc at r-project.org> writes:
> 
> > 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.
> 
> Perhaps some details on the required changes will help me see the
> light, but I would really like to see length(foo) be an error (no such
> method) when foo is an arbitary S4 class.

According to the Blue Book p.96 every S object has a length and 'An 
Introduction to R' repeats this.  So I believe an error is not an option.  
Indeed, from the wording, I think code could legitimately assume length(x) 
works and 0 <= length(x) and it is an integer (but not necessarily of type 
'integer').

Certainly functions and formulae have a length (different for functions in 
S and R, as I recall), and they are not 'vector-style'.

> I have encountered bugs due to accidental dispatch -- functions
> returning something other than an error because of the zero-length
> list implementation of S4.  It would not be surprising if some of the
> breakage caused by removing this "feature" identifies real bugs.
> 
> I was thinking that one of the main advatnages of the new S4 type was
> to get away from this sort of accidental dispatch.  Not trying to be
> snide, but what is useful about getting a zero for length(foo)?  The
> main use I can think of is in trying to identify S4 instances, but
> happily, that is no longer needed.
> 
> + seth

-- 
Brian D. Ripley,                  ripley at stats.ox.ac.uk
Professor of Applied Statistics,  http://www.stats.ox.ac.uk/~ripley/
University of Oxford,             Tel:  +44 1865 272861 (self)
1 South Parks Road,                     +44 1865 272866 (PA)
Oxford OX1 3TG, UK                Fax:  +44 1865 272595



More information about the R-devel mailing list