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?
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*
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With