NextMethod() explicit argument performance

194 views Asked by At

With the S3 object system, in a generic method you can delegate to the next method in a class hierarchy using the NextMethod() function. When Wickham describes this system at http://adv-r.had.co.nz/S3.html, he uses NextMethod() without any arguments in his example:

baz <- function(x) UseMethod("baz", x)
baz.C <- function(x) c("C", NextMethod())

I've always used NextMethod() without argument in my own code as well.


I just noticed that [.Date uses an explicit argument:

> `[.Date`
function (x, ..., drop = TRUE) 
{
    cl <- oldClass(x)
    class(x) <- NULL
    val <- NextMethod("[")
    class(val) <- cl
    val
}

The documentation for ?NextMethod says the following:

Normally 'NextMethod' is used with only one argument, 'generic'

In terms of performance, is calling NextMethod("generic") faster than NextMethod()? Is there any other reason to prefer one usage over the other?

0

There are 0 answers