Show source code for function in package in R

Possible duplicate:
R: show source code of function S4 in package

I downloaded the package ( GEOquery ) and played with some of the features. One of them is called Table , which, as far as I know, is able to tabulate the S4 dataset.

eg.

 > 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 would like to know the Table code so that I can know how to tabulate a GDS dataset, since data.frame and as.list cannot force the S4 class - although I can insert GDS dataset tables, for example,

 GDS_table=Table(GDS2853)[1:20000,1:20] #GDS2853 contains 20 columns and approx 17000 rows 

I tried 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 specifying β€œwhere” by inserting package=:GEOquery , but apparently package is an unused argument.

Interestingly, what I did wrong was to not see the source code for Table .

+4
source share
2 answers

From your output, it looks like Table is a common S4.

To see a list of your S4 methods, use showMethods() . To view a specific method, use getMethod() , passing the "signature" of the method you want along with the name of the function. ("Signature" is a character vector consisting of the class (s) of the argument (s) according to which the general Table implements its sending method, i.e. If you will do Table(GDS2853) , the signature will most likely be class(GDS2835) )

Here is an example that gets the code for the 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")) 
+8
source

In your example, this would be:

 getMethod("Table", "GEOData") 

You may also be interested in how to get help documentation for S4 methods that require an equally unusual call:

 method?Table("GEOData") 

As a rule, with S4 you will need

  • function name
  • class (signature) of objects that it is intended for

If you lost the last:

 class(object) 

will return the class, and you can also do:

 showMethods("Table") 

to show all currently available methods. As an alternative, I often use:

 findMethods("Table") 

and the reason is that findMethods returns a list of all methods for a particular function. Classes can have long names, and I find that I often make mistakes / do not capitalize them, since a quick hack, findMethods("functionname") convenient. Of course, it can also bite you for universal functions using many methods, since the printed list can be quite long.

+3
source

Source: https://habr.com/ru/post/969792/


All Articles