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

Robert Gentleman rgentlem at fhcrc.org
Mon Aug 21 19:55:48 CEST 2006



Prof Brian Ripley wrote:
> 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'.

   Yes, but that is because that in S(-Plus), and not in R, virtually 
every object was an instance of a "generic vector", including functions 
(formulas were white book, not blue, and I'm still not sure that 
indexing of them makes sense, but I am sure that indexing functions does 
not; it suggests, at least to me, that we want to emphasize 
implementation over semantics).

   Now, in R, since not everything is a generic vector, it is less clear 
what to do in some cases, and I am not going to argue too hard against 
everything having a length, but I think the number 1 is a much better 
choice than the number 0.  (the compromise solution of 0.5 has some 
charm :-)

   I am also scared that such reasoning will lead one to believe that 
indexing these things using [, or similar should work, and that leads to 
major problems, since I lost the argument about not indexing outside of 
array bounds some years ago. What would be sensible in that case? 
Certainly not what currently happens with S4 objects (in R release).

   best wishes
     Robert



> 
>> 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
> 

-- 
Robert Gentleman, PhD
Program in Computational Biology
Division of Public Health Sciences
Fred Hutchinson Cancer Research Center
1100 Fairview Ave. N, M2-B876
PO Box 19024
Seattle, Washington 98109-1024
206-667-7700
rgentlem at fhcrc.org



More information about the R-devel mailing list