Re: [Rd] question about trailing arguments in an S4 method

From: Seth Falcon <>
Date: Sun 17 Dec 2006 - 00:06:57 GMT

Ben Bolker <> writes:

> I'm trying to add arguments to the AIC method
> for some classes -- things like
> weights=TRUE to calculate AIC weights
> corr=TRUE, nobs to calculate AICc
> delta=TRUE to put a delta-AIC column in the output.
> The problem is that AIC is defined as
> AIC(object, ..., k=2) where k is the constant associated
> with the penalty term and ... is a list of objects
> that will have their AICs calculated and listed.
> Thus I'm not allowed (I think) to extend the definition to
> AIC(object, ..., nobs, corr=FALSE, delta=FALSE, weights=FALSE, k=2)

I think you can add args before the '...'. However, you will need to provide values for them in all calls or else they will steal a fit from the '...' args.

I don't understand really what you are trying to achieve, so this may not be helpful. Nevertheless, here is a dummy example that you may find useful.



setMethod("AIC", "Foo",
          function(object, weights=TRUE, delta=TRUE, ..., k=2) {
              ans <- AIC(object=object@fit, k=k, ...)
              args1 <- list(weights=weights, delta=delta, k=k)

foo <- new("Foo", fit=lm1)
## AIC(foo, lm1) # this doesn't work, lm1 gets picked up as the weights arg AIC(foo, weights=FALSE, delta=TRUE, lm1, lm1, lm1)

+ seth mailing list Received on Sun Dec 17 11:30:20 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 Sun 17 Dec 2006 - 06:30:54 GMT.

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