Questions tagged [r-s4]

One of the methods of object oriented programming in the R language.

647 questions
314
votes
3 answers

How to properly document S4 class slots using Roxygen2?

For documenting classes with roxygen(2), specifying a title and description/details appears to be the same as for functions, methods, data, etc. However, slots and inheritance are their own sort of animal. What is the best practice -- current or…
Paul 'Joey' McMurdie
  • 7,295
  • 5
  • 37
  • 41
137
votes
6 answers

What does "S3 methods" mean in R?

Since I am fairly new to R, I do not know what the S3 methods and objects are. I found that there are S3 and S4 object systems, and some recommend to use S3 over S4 if possible (See Google's R Style Guide at…
jiggysoo
  • 1,498
  • 2
  • 10
  • 9
88
votes
4 answers

R: what are Slots?

Does anyone know what a slot is in R? I did not find the explanation of its meaning. I get a recursive definition: "Slot function returns or set information about the individual slots of an objects" Help would be appreciated, Thanks - Alley
user573347
  • 975
  • 1
  • 7
  • 11
75
votes
7 answers

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

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…
Joris Meys
  • 106,551
  • 31
  • 221
  • 263
65
votes
2 answers

class in R: S3 vs S4

I want to create a class in R, should I use S3 or S4 class? I read a lot of different things about them, is there one superior to the other one?
RockScience
  • 17,932
  • 26
  • 89
  • 125
61
votes
2 answers

How to properly document S4 methods using roxygen2

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…
Paul 'Joey' McMurdie
  • 7,295
  • 5
  • 37
  • 41
58
votes
2 answers

Rd file name conflict when extending a S4 method of some other package

Actual question How do I avoid Rd file name conflicts when a S4 generic and its method(s) are not necessarily all defined in the same package (package containing (some of) the custom method(s) depends on the package containing the generic)…
Rappster
  • 12,762
  • 7
  • 71
  • 120
45
votes
3 answers

What does the @ symbol mean in R?

In packages like marray and limma, when complex objects are loaded, they contain "members variables" that are accessed using the @ symbol. What does this mean and how does it differ from the $ symbol?
pufferfish
  • 16,651
  • 15
  • 56
  • 65
42
votes
2 answers

Why, for an integer vector x, does as(x, "numeric") trigger loading of an additional S4 method for coerce?

While my question is related to this recent one, I suspect its answer(s) will have to do with the detailed workings of R's S4 object system. What I would expect: (TLDR; -- All indications are that as(4L, "numeric") should dispatch to a function…
Josh O'Brien
  • 159,210
  • 26
  • 366
  • 455
41
votes
1 answer

R hangs when there are too many arguments in setMethod (or setGeneric)

Basically, when there are many arguments in setMethod or (setGeneric) it works very slowly. Here is a basic example: setClassUnion(name = "mNumeric", members = c("missing", "numeric")) setClass(Class = "classA", representation = representation(ID =…
HBat
  • 4,873
  • 4
  • 39
  • 56
40
votes
3 answers

Sources on S4 objects, methods and programming in R

As I'm often confronted with situations where S4 programming is needed to keep an overview, I've collected quite some sources on S4 objects, methods and programming. I've listed them here as a reference. Please add your own sources as well. On the…
Joris Meys
  • 106,551
  • 31
  • 221
  • 263
37
votes
2 answers

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

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, …
Lisann
  • 5,705
  • 14
  • 41
  • 50
37
votes
2 answers

How to access the slots of an S4 object in R

I'm working with wavelets on a program and I'm used the package wavelets to create the DWT of a time series using the function dwt. This function returns an object of class dwt, which is a S4 object with many slots: W, V, levels, filter, and so…
zaire90
  • 713
  • 2
  • 6
  • 11
33
votes
1 answer

How to develop a package in R?

I have written some functions in R using S4 classes. Now I want to build an R package out of these functions. How should I proceed? Is there anything that I should do differently because I have used S4 classes?
MYaseen208
  • 22,666
  • 37
  • 165
  • 309
28
votes
6 answers

Which packages make good use of S4 objects?

Which R packages make good use of S4 classes? I'm looking for packages that use S4 appropriately (i.e. when the complexity of the underlying problem demands), are well written and well documented (so you can read the code and understand what's going…
hadley
  • 102,019
  • 32
  • 183
  • 245
1
2 3
43 44