[R-pkg-devel] Creating Accessor Methods

Joris Meys Joris.Meys at Ugent.be
Thu Mar 10 15:13:56 CET 2016


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
This is the other book : http://r-pkgs.had.co.nz/

Cheers
Joris

On Thu, Mar 10, 2016 at 3:05 PM, Glenn Schultz <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
> ______________________________________________
> R-package-devel at r-project.org mailing list
> https://stat.ethz.ch/mailman/listinfo/r-package-devel
>



-- 
Joris Meys
Statistical consultant

Ghent University
Faculty of Bioscience Engineering
Department of Mathematical Modelling, Statistics and Bio-Informatics

tel : +32 9 264 59 87
Joris.Meys at Ugent.be
-------------------------------
Disclaimer : http://helpdesk.ugent.be/e-maildisclaimer.php

	[[alternative HTML version deleted]]



More information about the R-package-devel mailing list