Douglas M. Bates and Saikat DebRoy
Converting a Large R Package to S4 Classes and Methods
******************************************************

The nlme package for fitting and examining linear and
nonlinear mixed-effects models in R is a required package and also
one of the largest R packages, based on source package size. In the
first phase of a project to extend the capabilities of the nlme
package to include generalized linear mixed models (glmm's), we
reimplemented linear mixed-effects (lme) models using S4 classes
and methods, as described in John Chambers' book "Programming with
Data" and as implemented in the methods package for R.
Our general goals for this phase are to incorporate new theoretical
and computational developments for the lme model and to provide a
faster, cleaner implementation of lme fits in R while including
hooks for later extensions to the glmm model and the nlme model. In
particular, we use our reStruct (random-effects structure) class in
iterative PQL fits for glmm's, based on Brian Ripley's function
glmmPQL from the MASS package.

As described in "Programming with Data", classes, slots and
inheritance relationships must be declared explicitly when using the
methods package. Although such formal declarations require package
authors to be more disciplined than when using informal S3 classes,
they provide assurance that each object in a class has the required
slots and that the names and classes of data in the slots are
consistent. This is important to us because we are trying to
achieve both efficiency and flexibility. We provide flexibility by
defining many classes and methods and by using multiple-argument
signatures in method declarations. We achieve efficiency by
implementing many methods in C code using the .Call interface and
through liberal use of GET_SLOT and SET_SLOT within the C code.

We feel that the new implementation is much cleaner and easier to
understand than the previous implementation, due in large part to
the more extensive use of classes and methods. It is definitely
faster and can handle larger problems than the previous
implementation.