The methods package in the r-devel code

A package, methods, has been added to the source repository for the 1.4 version of R.

The contents provide an implementation of formal classes and methods, treating the description in the book Programming with Data (aka the green book). The following notes introduce a few topics for discussion regarding R development. (The source of the package replaces, and updates, the Omegahat module R/Classes.)

  1. Where should the code reside?

    The code is currently being kept in a package, in the main CVS tree so it's guaranteed to be shipped with the corresponding development version of R.

    This may be a temporary situation, but it has the advantage that one can detach the package, if it turns out to break something else (e.g., see the next list item). Discussions so far suggest that in the long run at least part of the code will need to be pretty tightly bound to the evaluator for efficiency and to work well with some other new developments such as threading.

    The eventual choice may be to incorporate all of the package into the base. We should discuss this as things move along.

  2. Revised versions of class, etc.

    You will see when attaching methods that it overrides class. This is a potential source of non-compatibility with old-style class code. Details are in a separate note.

  3. Extensions to the Grammar

    The @ operator has been added for accessing slots--this is pretty trivial, but as it's implemented as a primitive, it is now in the base.

    I would also like to add a limited use of = for assignments: only to be allowed for top-level assignments or for elements of a braced list. The limitation removes any chance of the notorious

          if(x = 0) /* do something important */
    C bug, but still allows the PwD examples to be run. (It's also useful, I think, in bringing in new users who have programmed in C, Java, even Fortran.)

  4. S3 Classes and Methods

    We need eventually to decide how to deal with these, if it turns out we want to make S4-style methods the standard. The current implementation is fairly back-compatible, in the sense for example that one can treat matrices as a formal class and usually find that existing matrices conform. (Because R slots are implemented as attributes.)

    Some points for discussion are collected in a separate page.

  5. Inconsistencies with the Book

    The following are some of the main known differences from the description in Programming with Data.

John Chambers<>
Last modified: Mon Aug 13 14:59:33 EDT 2001