Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How do I show the source code of an S4 function in a package?

Tags:

r

packages

s4

I used the packages topGO in R to analyze gene enrichment with the following code:

sampleGOdata <- new("topGOdata", description = "Simple session", ontology = "BP",                     allGenes = geneList, geneSel = topDiffGenes, nodeSize = 10,                      annot = annFUN.db, affyLib = affyLib) resultFisher <- runTest(sampleGOdata, algorithm = "classic", statistic = "fisher") allRes <- GenTable(sampleGOdata, classicFisher = resultFisher, orderBy = "fisher",                     ranksOf = "classicFisher",topNodes = 10) 

I want to see and change the RunTest function and the GenTable function to change the ResultTable, but I don't know how to show the function. With the getAnywhere("GenTable") I do not get the hard code I want.

getAnywhere("GenTable") 

A single object matching ‘GenTable’ was found

It was found in the following places

package:topGO  namespace:topGO 

with value

function (object, ...) standardGeneric("GenTable") <environment: 0x16a30c10> attr(,"generic") [1] "GenTable" attr(,"generic")attr(,"package") [1] "topGO" attr(,"package") [1] "topGO" attr(,"group") list() attr(,"valueClass") character(0) attr(,"signature") [1] "object" attr(,"default") `NULL` attr(,"skeleton") function (object, ...) stop("invalid call in method dispatch to \"GenTable\" (no default method)", domain = NA)(object, ...) attr(,"class") [1] "standardGeneric" attr(,"class")attr(,"package") [1] "methods" 

How can I do this?

like image 628
Lisann Avatar asked May 09 '11 13:05

Lisann


People also ask

How can I get source code of AR package?

If you want to view the code built-in to the R interpreter, you will need to download/unpack the R sources; or you can view the sources online via the R Subversion repository or Winston Chang's github mirror.

How do I view functions in R?

To view all the contents of a defined object, use the View() function. Behind the scenes, the R calls utils::View() on the input and returns it invisibly. If the input is not a data frame, it is processed using a variant of as. data.


1 Answers

Use getMethod() and specify the signature. In your case, that could be eg :

getMethod("GenTable","topGOdata") 

to show the GenTable method for topGOdata objects. In this case, there is only a method defined for topGOdata objects. In case there are methods with different signatures, showMethods() will tell you which ones. In your case :

showMethods("GenTable") # Function: GenTable (package topGO) # object="topGOdata" 

You can get the code for the signature you want by specifying it in the getMethod() function.

like image 55
Joris Meys Avatar answered Sep 22 '22 20:09

Joris Meys