Questions tagged [reference-class]

Reference classes are a new (as of R 2.12) way of object-oriented programming in R, such that objects are not copied but are instead mutable. Like most pass-by-reference methodologies, they are particularly well-suited to work with large datasets.

R has three object oriented (OO) systems: S3, S4 and Reference Classes (sometimes referred to as R5, yet their official name is Reference Classes).

Reference Classes were introduced in R 2.12. They fill a long standing need for mutable objects that had previously been filled by non-core packages like R.oo, proto and mutatr.

There are two main differences between reference classes and S3 and S4:

  • Refclass objects use message-passing OO
  • Refclass objects are mutable: the usual R copy on modify semantics do not apply

These properties makes this object system behave much more like Java and C#. The implementation of reference classes is almost entirely in R code, they are a combination of S4 methods and environments.

See also

156 questions
0
votes
0 answers

How to load R reference classes stored in the inst folder?

I have some code that I want to run when a user loads my package. That code includes creating a reference class (Parent) and sourceing a file stored under inst. Here is a toy version: Parent <- setRefClass("Parent", methods = list( …
nachocab
  • 13,328
  • 21
  • 91
  • 149
0
votes
1 answer

Error message in R: "Arguments to methods() must be named, or one named list"

I'm new to creating classes and methods in R and am running into a problem that I haven't found much documentation on. I have created a class, 'DataImport', and am trying to add the method below: DataImport$methods(reducedImport <-…
tjnel
  • 643
  • 1
  • 9
  • 19
0
votes
1 answer

R: Change the fields' (slots') values of the class assigning a value to some other field

Assgning a value to one field, how can I make the other fields changing. Consider the following ReferenceClass object: C<-setRefClass("C", fields=list(a="numeric",b="numeric") , methods=list( seta = function(x){ a<<-x …
Max Li
  • 5,069
  • 3
  • 23
  • 35
-1
votes
1 answer

Recursive class in R

i'm trying to do an "node" Class in R, like in java: but the code pop up an error, "The class node doesn't exist when i'm creating the value "Next="node" is it not possible to do recursion in a class in R? or how could i do this? node <-…
-1
votes
1 answer

Use do.call to get information out of a list of RC/S4 objects

I have a defined reference class and a list: RCclass<-setRefClass("RCclass",field=list(info="character")) A<-RCclass$new(info="a") B<-RCclass$new(info="b") testList<-list(A,B) do.call(function(x){paste0(x$info)},testList) The do.call function…
chl111
  • 468
  • 3
  • 14
-2
votes
1 answer

Call Refenrence Class function by string

Is there a easy way to call a function of object of a reference class by string like a do.call("...",...) for standard functions in R?
Heiko
  • 83
  • 1
  • 8
1 2 3
10
11