How to find all functions with methods for a given class

I basically look for the opposite of methods(some_function) , which returns all the class methods that exist for this function. Is there an easy way to find all functions that have an explicit method for a given class of objects?
For example, methods(my_func) returns a bunch of myfunc.classname values. Is there a functions(my_class) that returns all functions using the func.my_class method?

+4
source share
2 answers

I think you want to specify a class argument and nothing generic.function in methods . Compare

 methods(as.matrix) [1] as.matrix.data.frame as.matrix.data.table* as.matrix.default [4] as.matrix.dist* as.matrix.noquote as.matrix.POSIXlt [7] as.matrix.raster* as.matrix.SpatialGridDataFrame* as.matrix.SpatialPixelsDataFrame* 

Using this, which returns methods for a generic class

 methods(class="matrix") [1] anyDuplicated.matrix as.data.frame.matrix as.data.table.matrix* as.raster.matrix* boxplot.matrix corresp.matrix* [7] determinant.matrix duplicated.matrix edit.matrix* head.matrix isSymmetric.matrix lda.matrix* [13] qda.matrix* relist.matrix* subset.matrix summary.matrix tail.matrix unique.matrix Non-visible functions are asterisked 

And that also seems to work for S4 classes, for example.

 methods(class="data.table") [1] $<-.data.table* [.data.table* [<-.data.table* all.equal.data.table* as.data.frame.data.table* [6] as.data.table.data.table* as.list.data.table* as.matrix.data.table* dim.data.table* dimnames.data.table* [11] dimnames<-.data.table* duplicated.data.table* format.data.table* head.data.table* is.na.data.table* [16] merge.data.table* na.omit.data.table* names<-.data.table* Ops.data.table* print.data.table* [21] subset.data.table* tail.data.table* transform.data.table* unique.data.table* within.data.table* 
+7
source

I think you are describing the concept of introspection and reflection (well known in Java).

Java introspection and reflection post with links here: Explicit Java introspection and reflection

I do not know what technology or language you are using, but perhaps you will find the equivalent.

Hope this helps! Goodbye!

0
source

All Articles