I'm basically looking for the opposite of methods(some_function)
, which returns all class-methods that exist for that function. Is there some easy way to search for all functions which have an explicit method
for a given object class?
For example, methods(my_func)
returns a pile of myfunc.classname
values. Is there a functions(my_class)
which would return all functions with a func.my_class
method?
Asked
Active
Viewed 151 times
4

Carl Witthoft
- 20,573
- 9
- 43
- 73
2 Answers
7
I think you want to supply an argument to class
and nothing to 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*
With this, which returns methods for the 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 this also seems to work for S4 classes as well, e.g.
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*

Simon O'Hanlon
- 58,647
- 14
- 142
- 184
-
1Now this is sad: a year later I completely forgot I'd asked this. Thank goodness for SO's search tools :-) – Carl Witthoft Jun 04 '14 at 17:50
0
I think you are describing the concept of introspection and reflection (well-known in Java).
A post about introspection and reflection in Java with links here : Java introspection and reflection
I don't know which technology or language you are using but maybe you will find the equivalent.
Hope this helps ! Bye !