Reputation: 42010
Is there a way in R to get a list of all methods defined on an S4 class, given the name of that class?
Edit: I know that showMethods
can show me all the methods, but I want to manipulate the list programmatically, so that's no good.
Upvotes: 7
Views: 3233
Reputation:
Also stumbled upon it, how about
library(sp)
attr(methods(class="SpatialPolygons"), "info")$generic
# Alternatively:
# attr(.S4methods(class="SpatialPolygons"), "info")$generic
This will directly yield a vector of method names.
Upvotes: 0
Reputation: 263331
Maybe this would be useful:
mtext <- showMethods(class="SpatialPolygons", printTo =FALSE )
fvec <- gsub( "Function(\\:\\s|\\s\\\")(.+)(\\s\\(|\\\")(.+$)",
"\\2", mtext[grep("^Function", mtext)] )
fvec
[1] ".quad" "[" "addAttrToGeom"
[4] "area" "as.data.frame" "click"
[7] "coerce" "coordinates" "coordnames"
[10] "coordnames<-" "coords" "disaggregate"
[13] "extract" "fromJSON" "isDiagonal"
[16] "isTriangular" "isValidJSON" "jsType"
[19] "over" "overlay" "plot"
[22] "polygons" "polygons<-" "rasterize"
[25] "recenter" "spChFIDs" "spsample"
[28] "spTransform" "text" "toJSON"
The original version did not properly extract the quoted non S4 generics in mtext such as:
[60] "Function \"jsType\":"
[61] " <not an S4 generic function>"
Upvotes: 7
Reputation: 4474
Maybe something like
library(sp)
x=capture.output(showMethods(class="SpatialPolygons"))
unlist(lapply(strsplit(x[grep("Function: ",x,)]," "),function(x) x[2]))
Upvotes: 0
Reputation: 162321
Are you looking for showMethods()
?
library(sp)
showMethods(class="SpatialPolygons")
Upvotes: 2