Re: [Rd] S4 accessors

From: Seth Falcon <>
Date: Wed 27 Sep 2006 - 15:34:38 GMT

John Chambers <> writes:

> There is a point that needs to be remembered in discussions of
> accessor functions (and more generally).
> We're working with a class/method mechanism in a _functional_
> language. Simple analogies made from class-based languages such as
> Java are not always good guides.
> In the example below, "a function foo that only operates on that
> class" is not usually a meaningful concept in R.

If foo is a generic and the only method defined is for class Bar, then the statement seems meaningful enough?

> Functions are first-class objects and in principle every function
> should have a "function", a purpose. Methods implement that purpose
> for particular combinations of arguments.
> Accessor functions are therefore a bit anomalous.

How? A given accessor function has the purpose of returning the expected data "contained" in an instance. It provides an abstract interface that decouples the structure of the class from the data it needs to provide to users.

The anomaly, is IMO, a much larger challenge with generic function based systems. When the same name for a generic is used in different packages, you end up with a masking problem. This scenario is unavoidable in general, but particularly likely, for accessors. As S4 becomes more prevalent, I suspect that '<pkg>::foo' is going to become a required idiom for interactive use (other options are available for package code).

+ seth mailing list Received on Thu Sep 28 01:36:19 2006

Archive maintained by Robert King, hosted by the discipline of statistics at the University of Newcastle, Australia.
Archive generated by hypermail 2.1.8, at Wed 27 Sep 2006 - 18:30:09 GMT.

Mailing list information is available at Please read the posting guide before posting to the list.