Skip to content
Prev 23261 / 63424 Next

question about trailing arguments in an S4 method

Ben Bolker <bolker at zoo.ufl.edu> writes:
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.


setClass("Foo",
         representation=representation(
           fit="lm"))

setMethod("AIC", "Foo",
          function(object, weights=TRUE, delta=TRUE, ..., k=2) {
              ans <- AIC(object=object at fit, k=k, ...)
              args1 <- list(weights=weights, delta=delta, k=k)
              cat("args\n")
              print(args1)
              cat("answer:\n")
              print(ans)
          })

example("AIC")
foo <- new("Foo", fit=lm1)
AIC(foo)
## 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