[Rd] S4 setMethod, setGeneric and default arguments

evilphil phil.joubert at landg.com
Thu Nov 11 13:13:51 CET 2010

Hi Guys

I have defined a generic function, for which one of the arguments has a

setGeneric( "getFwdRate",
              function(.Object, tenorFrom, tenorTo=tenorFrom)

Then I have defined a method which also has a default:

setMethod( "getFwdRate", signature(.Object="CCurveVector",
tenorFrom="numeric", tenorTo="numeric"),
              function(.Object, tenorFrom, tenorTo=tenorFrom+1) {

However, if I call

getFwdRate(thisYC, 1)

I get "Error in function (classes, fdef, mtable)  :  unable to find an
inherited method for function "getFwdRate", for signature "CCurveVector",
"numeric", "missing" "

Is there a way that this call would match the method I've defined? Or do I
need to declare a duplicate method with signature(.Object="CCurveVector",
tenorFrom="numeric", tenorTo="missing")? In which case what is the point of
having default arguments in the method declaration?

View this message in context: http://r.789695.n4.nabble.com/S4-setMethod-setGeneric-and-default-arguments-tp3037716p3037716.html
Sent from the R devel mailing list archive at Nabble.com.

More information about the R-devel mailing list