From ripley at stats.ox.ac.uk  Mon Feb  6 20:44:50 2006
From: ripley at stats.ox.ac.uk (Prof Brian Ripley)
Date: Mon, 6 Feb 2006 19:44:50 +0000 (GMT)
Subject: [Rd] match gets confused by S4 objects
In-Reply-To: <m2hd7cjnse.fsf@ziti.local>
References: <m2hd7cjnse.fsf@ziti.local>
Message-ID: <Pine.LNX.4.61.0602061925190.4469@gannet.stats>

An S4 object is just a list with attributes, so a vector type.  match() 
works with all vector types including lists, as you found out (or could 
have read).

If in the future those proposing it do re-implement an S4 object as an new 
SEXP then this will change, but for now the cost of detecting objects 
which might have an S4 class defined somewhere is just too high (and would 
fall on those who do not use S4 classes).

On Mon, 6 Feb 2006, Seth Falcon wrote:

> If one accidentally calls match(x, obj), where obj is any S4 instance,
> the result is NA.
>
> I was expecting an error because, in general, if a match method is not
> defined for a particular S4 class, I don't know what a reasonable
> default could be.  Specifically, here's what I see
>
> setClass("FOO", representation(a="numeric"))
> foo <- new("FOO", a=10)
> match("a", foo)
> [1] NA
>
> And my thinking is that this should be an error, along the lines of
> match("a", function(x) x)
>
> Unless, of course, a specific method for match, table="FOO" has been
> defined.


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



[Rd] match gets confused by S4 objects
Prof Brian Ripley