Questions tagged [r-s3]

One of the object oriented systems in the R language.

S3 is the main object oriented system in R.
Read more about it here

Base R uses S3.
The other two common object oriented systems are S4 and R5.

149 questions
0
votes
0 answers

Documenting generic S3 methods in R so that user can see documentation?

I am extending the print() function by a method print.dmdSchemeSet(). This functions has additional arguments which I obviously have documented in the source files using roxygen2: #' Generic print function for \code{dmdSchemeSet} #' #' @param x…
Rainer
  • 8,347
  • 1
  • 23
  • 28
0
votes
1 answer

mlr package - Trying to integrate a new clustering learner. Default values in par.vals are being ignored (within makeRLearnerCluster method)

I am trying to integrate the MiniBatchKmeans function of package ClusterR to mlr. As per the docs, I have made the following changes: Created makeRLearner.cluster.MiniBatchKmeans Created trainLearner.cluster.MiniBatchKmeans Created…
prasiddhi
  • 1
  • 1
0
votes
2 answers

How could I define an application method on an S3 object in R? (like a "function object" in c++)

The problem I am trying to tackle here is needing to apply (execute) an S3 object which is essentially a vector-like structure. This may contain various formulas which at some stage I need to evaluate for a single argument, in order to get back a…
Alex Gian
  • 482
  • 4
  • 10
0
votes
0 answers

Add class to data.frame column by reference

I want to create a subclass for data.frame (and the like). I want a function that creates the class information and another that removes it. df <- data.frame(x = 1:10) This would be the “R sanctioned” way of adding classes, I think. And adding and…
Elio Campitelli
  • 1,408
  • 1
  • 10
  • 20
0
votes
0 answers

S3 method for class not imported in package

We have multiple methods for different classes in our R package, but all of them are so far from packages we import in the Description. Now, we want to write more methods for classes that are so far no dependency of our package. This works fine, if…
Marco
  • 71
  • 1
  • 1
  • 6
0
votes
1 answer

Extending apply function to S3 (like with print or plot)

I am working on a pet project in R that builds out a custom S3 class named groupr. I have written a few functions with dot notation (print.groupr, subset.groupr) as described in the Hadley tutorial, but I would like to extend the apply function and…
Alex Thompson
  • 506
  • 5
  • 13
0
votes
1 answer

dynamic class coercion in R

is there a way to dynamically coerce an object in R? Background I am trying to create a function factory for summary which can return the specific method based on the class of the object passed. Particularly, this is for one of the questions in…
Krishna
  • 415
  • 1
  • 4
  • 11
0
votes
1 answer

How to treat an object of a class same as another for a generic

I have classified an object to NewClass, how can I use a function, say plot, on the object as if It's of a known class, say hist?
ChuckP
  • 161
  • 1
  • 6
0
votes
0 answers

Overload S3 write function

I'm currently working on S3-classes trying to generate a write-function for my class. Just a minimal example: testclass <- function() { value <- list(c(1,2)) attr(value, "class") <- "testclass" value } print.testclass <- function(obj)…
groebsgr
  • 131
  • 1
  • 14
0
votes
0 answers

S3 Local Environment Approach, wiithout environment

I'm going through the following S3-Tutorial: http://www.cyclismo.org/tutorial/R/s3Classes.html I like the "Local Environment Approach" (and can live with its disadvantages). But I d'ont understand why there is the manual creation of a local…
Fabian Gehring
  • 1,133
  • 9
  • 24
0
votes
1 answer

Get list of datatypes with S3 generic function

I try to write a function where I can throw in a abitrary number of objects and get a list of the datatypes of that objects. This is a personal task to learn S3 Generics. What I have done so far is: myTypes <- function(x, ...) { dots <- list(...) …
ruedi
  • 5,365
  • 15
  • 52
  • 88
0
votes
1 answer

Methods dispatch for S3 classes in R: specifying method for particular subclass of multiple higher classes

I'm working on a collection of scripts and using s3 classes and methods to keep things a little cleaner. The class structure has three levels. Level 1: data.frame Level 2: sample_report OR fix_report Level 3: stim_report I want to write a…
jwdink
  • 4,824
  • 5
  • 18
  • 20
0
votes
1 answer

Using OOP and S3 methods to detect, then operate on a single vector OR all columns of a data.frame

I wrote a function that operates on a single vector. Sometimes I want to use that function on whole data.frame. I can accomplish that by using sapply across the relevant variables, but now I want contain and direct the function using S3…
Christian Lemp
  • 385
  • 1
  • 3
  • 10
0
votes
1 answer

Using S3 methods to bundle arguments into a data frame in R

I have created a function which has a reasonably large number of parameters (all vectors of the same length) and I thought it would make life easier to be able to bundle up the parameters in a data frame. I have managed to achieve this using S3…
seancarmody
  • 6,182
  • 2
  • 34
  • 31
1 2 3
9
10