show source code for a function in a package in R
r, r-s4
Solution
From the output you posted, it looks like `Table` is an S4 generic.
To view a list of its S4 methods, use `showMethods()`. To view a particular method, use `getMethod()`, passing in the 'signature' of the method you want along with the name of the function. (A 'signature' is a character vector composed of the class(es) of the argument(s) according to which the generic `Table` performs its method dispatch. i.e. if you will be doing `Table(GDS2853)`, the signature will likely be `class(GDS2835)`)
Here's an example that gets the code for an S4 method in the sp package:
library(sp)
showMethods("overlay")
# Function: overlay (package sp)
# x="SpatialGrid", y="SpatialPoints"
# x="SpatialGrid", y="SpatialPolygons"
# x="SpatialGridDataFrame", y="SpatialPoints"
# x="SpatialGridDataFrame", y="SpatialPolygons"
# x="SpatialPixels", y="SpatialPoints"
# x="SpatialPixelsDataFrame", y="SpatialPoints"
# x="SpatialPoints", y="SpatialPolygons"
# x="SpatialPointsDataFrame", y="SpatialPolygons"
# x="SpatialPolygons", y="SpatialGrid"
# x="SpatialPolygons", y="SpatialPoints"
getMethod("overlay", signature=c("SpatialGrid", "SpatialPoints"))
Problem
Possible Duplicate: R: show source code of an S4 function in a package I downloaded a package (`GEOquery`) and was playing with some of the functions. One of them is called `Table`, which, to my understanding, is able to tabulate an `S4` dataset. E.g. ``` > summary(GDS2853) # GDS2853 is a dataset I downloaded from NCBI Length Class Mode 1 GDS S4 ``` `getAnywhere(Table)` shows ``` > getAnywhere(Table) A single object matching ‘Table’ was found It was found in the following places package:GEOquery namespace:GEOquery with value function (object) standardGeneric("Table") <environment: 0x06ad5268> attr(,"generic") [1] "Table" attr(,"generic")attr(,"package") [1] "GEOquery" attr(,"package") [1] "GEOquery" attr(,"group") list() attr(,"valueClass") character(0) attr(,"signature") [1] "object" attr(,"default") `\001NULL\001` attr(,"skeleton") function (object) stop("invalid call in method dispatch to \"Table\" (no default method)", domain = NA)(object) attr(,"class") [1] "standardGeneric" attr(,"class")attr(,"package") [1] "methods" ``` I'd like to learn the code of `Table` so that I could know how to tabulate a GDS dataset, as `data.frame` and `as.list` couldn't coerce an `S4` class - although I could tabulate GDS dataset by, for example, ``` GDS_table=Table(GDS2853)[1:20000,1:20] #GDS2853 contains 20 columns and approx 17000 rows ``` I tried the `getMethods` as suggested in other posts but below is what I got ``` > getMethod("Table") Error in getMethod("Table") : No method found for function "Table" and signature ``` I also tried to specify the "where" by putting in `package=:GEOquery` but apparently `package` is an unused argument. Wonder what I did wrong so as to fail to see the source code for `Table`.