I'm having some trouble writing some code that dispatches on matrices. To assist me, I'd like to see what generic functions in the base library dispatch on matrices. Is there any way to get R to give me a list of them? Failing that, does anyone know of any members of that list?
Asked
Active
Viewed 99 times
1 Answers
3
There are at least seven functions in base R that have matrix generics:
anyDuplicated
determinant
duplicated
isSymmetric
subset
summary
unique
you can get them with
getS3method("anyDuplicated", class="matrix")
or just
anyDuplicated.matrix
Found using
Filter(function(x) {
!is.null(getS3method(x, class="matrix", optional=TRUE))
},ls(all.names=TRUE, env = baseenv()))

MrFlick
- 195,160
- 17
- 277
- 295
-
Are you sure about that code at the bottom? When I run it, I get `character(0)` and `Warning message: In findGeneric(f, envir) : 'kronecker' is a formal generic function; S3 methods will not likely be found` – J. Mini Feb 21 '21 at 15:16
-
@J.Mini I get that warning too. Seems safe enough to ignore. I removed the explicit check for `isGeneric` which should be more forgiving. I may have had a different package loaded which changed the default behavior. – MrFlick Feb 21 '21 at 19:17
-
Seems to have done the trick. My output is now: ```[1] "anyDuplicated" "as.data.frame" "determinant" "duplicated" [5] "isSymmetric" "subset" "summary" "unique" Warning message: In findGeneric(f, envir) : 'kronecker' is a formal generic function; S3 methods will not likely be found``` – J. Mini Feb 22 '21 at 01:09