[R-pkg-devel] Creating Accessor Methods

Glenn Schultz glennmschultz at me.com
Thu Mar 10 22:04:25 CET 2016


Hello Joris,

Thank worked perfectly.  My main concern was that I was creating multiple methods which may have the same name but different signature. Just over thinking things I guess but I appreciate your time answering my question.

Glenn

> 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
> ______________________________________________
> R-package-devel at r-project.org <mailto:R-package-devel at r-project.org> mailing list
> https://stat.ethz.ch/mailman/listinfo/r-package-devel <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 <http://helpdesk.ugent.be/e-maildisclaimer.php>

	[[alternative HTML version deleted]]



More information about the R-package-devel mailing list