[R] showMethods doubt

Douglas Bates bates at stat.wisc.edu
Thu Jun 2 16:20:33 CEST 2005


Ernesto Jardim wrote:
> Hi,
> 
> I'm developing in S4 and I wanted to see the methods for a specific
> class using showMethods but I didn't succed. Can someone help ? See the
> example below.
> 
> setClass("myclass",
>     representation(
>         name    ="character"
>     )
> )
> 
> setGeneric("mymeth", function(obj, ...){
>     standardGeneric("mymeth")
>     }
> )
> 
> setMethod("mymeth", signature("myclass"), function(obj){
>     print(paste("Hi,", obj at name, "and I don't know what to do with
> showMethods !"))
>     }
> )
> 
> Now if you do:
> 
>> myobj <- new("myclass", name="my name is joe")
>> mymeth(myobj)
> [1] "Hi, my name is joe and I don't know what to do with showMethods !"
> 
> So the method is working, let's use showMethods:
> 
>> showMethods(classes="myclass")
> 
> Function "addNextMethod":
> <Empty Methods List>
> 
> Function "body<-":
> <Empty Methods List>
> 
> Function "coerce":
> <Empty Methods List>
> 
> Function "initialize":
> .Object = "myclass"
>     (inherited from .Object = "ANY")
> 
> Function "loadMethod":
> <Empty Methods List>
> 
> Function "show":
> object = "myclass"
>     (inherited from object = "ANY")
> NULL
> 
> mymeth does not show on that list, why ?

Try

showMethods(classes = "myclass", where = .GlobalEnv)

I believe the convention is that unless you give showMethods a generic
function as argument `f' it will look for the generics in "package:methods".




More information about the R-help mailing list