On Mar 10, 2016, at 8:13 AM, Joris Meys <Joris.Meys at Ugent.be> wrote:
Hi Glenn,
that is actually as easy as defining a generic and defining a method for each class to extract the slot. I do this literally in every package I write.
setGeneric('duration', function(x, ...) standardGeneric('duration')
setMethod('duration', signature = 'MBSCashFlow', function(x) { x at Duration})
setMethod('duration', signature = 'REMICCashFlow', function(x) {x at Duration})
etc...
I suggest you take a close look at Hadley Wickham's books 'Advanced R' and 'R packages', both freely available online.
This is the relevant section of the first book : http://adv-r.had.co.nz/OO-essentials.html <http://adv-r.had.co.nz/OO-essentials.html>
This is the other book : http://r-pkgs.had.co.nz/ <http://r-pkgs.had.co.nz/>
Cheers
Joris
On Thu, Mar 10, 2016 at 3:05 PM, Glenn Schultz <glennmschultz at me.com <mailto:glennmschultz at me.com>> wrote:
All,
I have a package with to S4 classes (MBSCashFlow, REMICCashFlow and BondCashFlow) all of which contain the slot Duration. I would like have an accessor Duration that would work on multiple signatures. Is this possible? I have checked my books, help, BioConductor tutorials and it appears that this is not possible. Has anyone ever run into this situation?
Best Glenn