Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How can I get a list of all methods defined on an S4 class in R?

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.

like image 992
Ryan C. Thompson Avatar asked Oct 01 '13 20:10

Ryan C. Thompson


2 Answers

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>" 
like image 145
IRTFM Avatar answered Oct 11 '22 14:10

IRTFM


Are you looking for showMethods()?

library(sp)
showMethods(class="SpatialPolygons")
like image 21
Josh O'Brien Avatar answered Oct 11 '22 15:10

Josh O'Brien