Skip to content
Prev 54846 / 63424 Next

How to modify dots and dispatch NextMethod

2018-02-22 12:39 GMT+01:00 Tomas Kalibera <tomas.kalibera at gmail.com>:
I meant with a named function inside do.call, instead of an anonymous
one. For example:

c.foo <- function(..., recursive=FALSE) {
  message("calling c.foo...")
  dots <- list(...)
  # inspect and modify dots; for example:
  if (length(dots > 1))
    dots[[2]] <- 2
  do.call(
    c.foo.proxy,
    c(dots, recursive=recursive)
  )
}

c.foo.proxy <- function(..., recursive=FALSE)
structure(NextMethod("c"), class="foo")

Right now, the effect of the code above is the same as with the
anonymous function. Shouldn't it issue a similar error then?
My only concern about this workaround is that it triggers the dispatch
stack again from the beginning of the class hierarchy, which seems not
very elegant nor efficient.
I?aki