From jmc at r-project.org  Fri Mar  6 23:12:00 2009
From: jmc at r-project.org (John Chambers)
Date: Fri, 06 Mar 2009 14:12:00 -0800
Subject: [Rd] S4 objects for S3 methods
Message-ID: <49B19FB0.9030606@r-project.org>

Some modifications have been committed for the r-devel version today 
that modify (essentially, correct a bug in) the communication of objects 
to an S3 method from an S4 class that extends the S3 class.

This is one of a sequence of changes designed to make S4 classes work 
more generally and consistently with S3 methods and classes.

In 2.8.0, support was provided for S4 classes that extend S3 classes, 
partly by making S3 method dispatch recognize the inheritance.

The catch was that the S3 method would get the S4 object.  Two problems 
with that:

1. The S3 method would fail if it tried to use the S3 class information 
directly, since the class attribute was the S4 class.

2. More seriously, if the method used the object, modified it and 
returned the result, it had a good chance of returning an invalid object 
seeming to come from the S4 class.

The modification to deal with this now delivers to the S3 method the 
inherited S3 object.  (This turned out to be somewhat harder than the 
original change, since it impacts several pieces of internal code.)  A 
revision of the function asS4() deals with similar concerns--see the 
documentation.

The change does not affect default methods.  It would be tempting to 
convert S4 objects for those, but some S3 generics attempt to deal with 
S4 objects, e.g., str().  A change to the primitives that dispatch 
methods is more plausible, but for the moment all that was added was 
more explicit error messages if a non-vector S4 object is supplied.

For more information see the section on inheriting from non-S4 classes 
in the documentation ?Classes.

It would be helpful if package maintainers would check this and previous 
changes by running their code against the r-devel version of R, before 
that becomes 2.9.0.  Please report any new errors (provided, of course, 
that the same code works with 2.8.1).

John



[Rd] S4 objects for S3 methods
John Chambers