Skip to content
Prev 15131 / 63424 Next

Canonical S4 Method signature

Paul Roebuck schrieb:
Hi,

maybe the following is a starting point and comes close to what you want ...

Matthias


if(!isGeneric("foo"))
    setGeneric("foo", function(m, n) standardGeneric("foo"))

setMethod("foo", signature(m = "missing", n = "numeric"),
    function(n){ 
        # do something
        # for example
        print(n)
    })

setMethod("foo", signature(m = "numeric", n = "numeric"),
    function(m, n){ 
        # do something
        # for example
        print(m)
        print(n)
    })

foo(3, 4)
foo(n = 3, 4)
# unfortunatelly you have to do
foo(,3)
# or
foo(n = 3)