s4

show source code for a function in a package in R [duplicate]

心不动则不痛 提交于 2019-12-18 05:11:32
问题 This question already has answers here : Closed 7 years ago . 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

show source code for a function in a package in R [duplicate]

六月ゝ 毕业季﹏ 提交于 2019-12-18 05:11:14
问题 This question already has answers here : Closed 7 years ago . 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

How to properly document S4 “[” and “[<-“ methods using roxygen?

风流意气都作罢 提交于 2019-12-17 22:39:41
问题 Below I posted a mini example in which I want do write documentation for an “[“ method for a S4 class. Does someone know how to properly document a method for the generic "[" using roxygen and S4? I get a warning when checking the package after building (see below). #' An S4 class that stores a string. #' @slot a contains a string #' @export setClass("testClass", representation(a="character")) #' extract method for testClass #' #' @docType methods #' @rdname extract-methods setMethod("[",

When does it pay off to use S4 methods in R programming

混江龙づ霸主 提交于 2019-12-17 22:04:59
问题 I program regularly in R in a professional context, and I write packages for clients or co-workers as well. Some of the programmers here have a Java background and insist on doing everything the object-oriented way, using S4 methods. My experience on the other hand is that S4 implementations often perform worse and cause a lot more headache when trying to get the code do what you want it to do. I definitely agree that in some cases, you have to be able to construct complex objects or append

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

孤街浪徒 提交于 2019-12-17 17:39:39
问题 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

How to properly document S4 methods using roxygen2

谁说胖子不能爱 提交于 2019-12-17 17:28:29
问题 I've seen some discussions in SO and other places regarding how this should be or will be done in future versions of Roxygen2. However, I am stuck. How should I go about documenting a S4 generic, as well as its methods, using Roxygen2? A working example for a brand new generic/methods, as well as an example for extending base S4 generic would be incredibly useful. I do not want to have to make separate (mostly) redundant documentation for each S4 method of the same generic. Due dilligence: I

setMethod and package Matrix

老子叫甜甜 提交于 2019-12-14 02:46:50
问题 I am creating an S4 class that uses package Matrix and then using setMethod to redefine "sin" for my class > library(Matrix) > setClass("foo",slots=list(z="Matrix")) > setMethod("sin",signature(x="foo"),function(x){return(cos(x@z))}) [1] "sin" however, even before I get started using my class I encounter a problem > y<-Matrix(c(1,2,1,2),2,2) > sin(y) 2 x 2 Matrix of class "dgeMatrix" [,1] [,2] [1,] 0.8414710 0.8414710 [2,] 0.9092974 0.9092974 > sin(y) Error in match(x, table, nomatch = 0L) :

Overloading + operator in R S4 classes and Matrix package

偶尔善良 提交于 2019-12-13 15:32:27
问题 I get a weird effect when trying to overload the + operator and using the Matrix package with sparse matrices. I first define a very simple class that does not use the Matrix package but has a + operator. I then sum two sparse matrices. The first M+M addition delivers the expected result but the second throws an error. Here is a very simple code that generates the error: require(Matrix) setClass("TestM",representation(M='numeric')) setMethod("initialize", "TestM", function(.Object,x) {

Writing an S4 generic method with two arguments

好久不见. 提交于 2019-12-13 04:26:16
问题 I am trying to define my own S4 class with a generic method. setClass("MultiplyObject", representation(the.factor = "numeric")) # Create a new instance of a class with the "new" method multobj <- new("MultiplyObject", the.factor = 3) # Create a new generic function definition setGeneric("ActOnNumber", function(object, n) { standardGeneric("ActOnNumber", n) }) # Define the ActOnNumber method for the MultiplyObject class setMethod("ActOnNumber", signature(object = "MultiplyObject", n = "numeric

Looping through variables in dynamically created S4 class in R

拜拜、爱过 提交于 2019-12-12 19:19:38
问题 I'm working with an R program where I've dynamically created an S4 class. I would like to somehow loop through each of the variables in this class to write to a table. classStructure <<- getColumns(jobClass) myclass <- setClass("myclass", slots = classStructure) method <<- setClassMethods() setClassMethods <- function(){ setGeneric("myclass", def = function(myclassVar, level, outFile){ standardGeneric("myclassMethod") }) setMethod("myclassMethod", signature = "myclass", function(myclassVar,