[Phylobase-devl] setGeneric vs. setMethod

Ben Bolker bolker at ufl.edu
Mon Jun 23 00:44:29 CEST 2008


  I wrote this stuff, following my nose/best guess about S4 stuff.  If 
you have a better way to
do it, go for it!

  cheers
    Ben


Peter Cowan wrote:
> Hey all,
>
> I'd like to add a new generic 'reorder'.  I was looking through the
> generics and methods and is appears that for each function we each.
> For example the generic "hasNodeLabels" is coded in the following way.
>
> In methods-phylo4.R there exists:
>
> setMethod("hasNodeLabels", "phylo4", function(x) {
>     length(x at node.label) > 0
> })
>
> In the phylo4.R there exists:
>
> setGeneric("hasNodeLabels", function(x) {
>     standardGeneric("hasNodeLabels")
> })
>
>
> My understanding is that the setGeneric calls the method
> standardGeneric() to define the function.  However, my understanding
> is that these doesn't set the default, it uses the previously set
> 'hasNodeLabels'.  My question is why do we set Generics in this
> manner?  Couldn't we also do:
>
> setGeneric("hasNodeLabels", useAsDefault = function(x) {
>     length(x at node.label) > 0
> })
>
> (maybe also setting the group parameter, which I don't quite grok)
>
> Thanks
>
> Peter
> _______________________________________________
> Phylobase-devl mailing list
> Phylobase-devl at lists.r-forge.r-project.org
> https://lists.r-forge.r-project.org/cgi-bin/mailman/listinfo/phylobase-devl
>   



More information about the Phylobase-devl mailing list