>>>>> "DS" == Dario Strbenac <D.Strbenac at
garvan.org.au>
>>>>> on Fri, 3 Sep 2010 12:00:14 +1000 (EST) writes:
DS> Hello,
DS> If the signature of a method defines which generic it implements then
I'm confused about why this minimal example I invented won't work :
very short answer:
if(FALSE) { 0 == 1 }
slightly longer:
if( something_wrong ) { anything_can_be_put_here }
In other words:
Your assumption is wrong.
There's only one generic and potentially many methods, defined
via signatures, but you have not understood what a signature is.
DS> setGeneric("myFun", function(rs,
...){standardGeneric("myFun")})
DS> setGeneric("myFun", function(cs,
...){standardGeneric("myFun")})
DS> setMethod("myFun", "numeric", function(rs, colour
= "Blue")
DS> {
DS> cat(rs*100, colour)
DS> })
DS> setMethod("myFun", "character", function(cs,
colour = "Red")
DS> {
DS> cat(cs, colour)
DS> })
Rather:
setGeneric("myFun", function(x, ...)
standardGeneric("myFun"))
setMethod("myFun", "numeric",
function(x, colour = "Blue") cat(xs*100, colour))
## etc
where the last is an abbreviated form of
setMethod("myFun", signature(x = "numeric"),
function(x, colour = "Blue") cat(xs*100, colour))
which is abbreviated for
setMethod("myFun", signature = signature(x = "numeric"),
function(x, colour = "Blue") cat(xs*100, colour))
I do wonder why the examples on the ?setMethod
help page where not sufficient here..
DS> Thanks for any tips,
you're welcome.
Martin Maechler, ETH Zurich
DS> --------------------------------------
DS> Dario Strbenac
DS> Research Assistant
DS> Cancer Epigenetics
DS> Garvan Institute of Medical Research
DS> Darlinghurst NSW 2010
DS> Australia
DS> ______________________________________________
DS> R-devel at r-project.org mailing list
DS> https://stat.ethz.ch/mailman/listinfo/r-devel>>>>> "DS" == Dario Strbenac <D.Strbenac at
garvan.org.au>
>>>>> on Fri, 3 Sep 2010 12:00:14 +1000 (EST) writes:
DS> Hello, If the signature of a method defines which
DS> generic it implements then I'm confused about why this
DS> minimal example I invented won't work :
DS> setGeneric("myFun", function(rs,
DS> ...){standardGeneric("myFun")})
setGeneric("myFun",
DS> function(cs, ...){standardGeneric("myFun")})
DS> setMethod("myFun", "numeric", function(rs, colour
DS> "Blue") { cat(rs*100, colour) })
DS> setMethod("myFun", "character", function(cs,
colour DS> "Red") { cat(cs, colour) })
DS> Thanks for any tips, Dario.
DS> -------------------------------------- Dario Strbenac
DS> Research Assistant Cancer Epigenetics Garvan Institute
DS> of Medical Research Darlinghurst NSW 2010 Australia
DS> ______________________________________________
DS> R-devel at r-project.org mailing list
DS> https://stat.ethz.ch/mailman/listinfo/r-devel