The R6 package provides a type of class which is similar to R’s standard reference classes, but it is more efficient and doesn’t depend on S4 classes and the methods package
Questions tagged [r6]
181 questions
2
votes
1 answer
R: How to overload + operator to call a method which adds a function to an R6 class?
My aim is to overload the + operator in order to call a method on an R6 object. Here is a toy example with an R6 object of class aclass that has a method add_function(foo) to store some arbitrary function in itself.
I want to substitute the call to…

JBJ
- 866
- 9
- 21
2
votes
1 answer
Call method from method inside same class
I am trying to create a flow structure in an object that is based on a class.
I have 4 methods (where 3 methods should be called from the method [run()].
Question:
Should you be able to call a method from another method assuming you are in the same…

Toolbox
- 2,333
- 12
- 26
2
votes
1 answer
How to add functions in a loop to R6Class in R
I want to write wrapper over R6Class but it don't work, I've tried multiple things after I've found this question dynamically add function to r6 class instance
So I've tried this, they both don't work:
get <- function(x = list()) {
class <-…

jcubic
- 61,973
- 54
- 229
- 402
2
votes
1 answer
Changing cloning behavior in R6 classes
Suppose I have an R6 class and one of it's elements is an external pointer pointing to some C++ object.
So I have something like this:
myClass <- R6::R6Class(
"myClass",
public = list(
xp = NULL,
initialize = function(x) {
self$xp…

Daniel Falbel
- 1,721
- 1
- 21
- 41
2
votes
0 answers
"unlock" R6 class only durring initialize
I want to dynamically add methods to an R6 class, but only during initialize(). For this I must set lock_objects to FALSE. Is there a not-to-hacky way to lock the object again at the end of initialize()?

Stefan F
- 2,573
- 1
- 17
- 19
2
votes
1 answer
Using set to dynamically construct R6 class and instance
I'd like to create a function create_thresholds that dynamically creates an R6 class and an instance object. The idea is to dynamically create a data structure that has read-only active fields that client-objects can access similar to the example…

Brandon Loudermilk
- 960
- 8
- 18
2
votes
1 answer
R - R6 class as a rigid "read-only" data structure
In large projects I sometime want to have a standardized and rigid data 'object' such that any function of that data may confidently assume numerous properties of the object with no more than an assertion that the object is of the expected class. So…

zkurtz
- 3,230
- 7
- 28
- 64
2
votes
0 answers
How to completely clone an R6Class Generator
I am developing an R package and use R6 internally. I have two R6 objects:
A Foo object which contains lots of data and methods of summarize the whole data;
A Bar object which contains subsetting methods of Foo's data and methods of query that…

hongyuanjia
- 21
- 1
2
votes
0 answers
Issue on using R6 classes and foreach() %dopar% together
I'm having an issue on R6 classes when used with foreach() together, possibly to do with environments (I'm using Windows).
Suppose that there are two R6 classes, "class1" and "class2". method1 in class1 is dependent on class2 (see example code below…

Min
- 179
- 9
2
votes
0 answers
R6 class not recognized in S4 %*% method
I have an R6 class that I wish to have the %*% method defined. I have seen in another question how to accomplish this with a new S4 method. However, I have tried this approach and it fails when I try to create the S4 %*% method for my R6 class. …

cdeterman
- 19,630
- 7
- 76
- 100
2
votes
0 answers
R6 inheritance & virtual classes issue
(first post to Stack Overflow so maybe I didn't post where/how I should, sorry)
TL;DR : How do I make this specific inheritance scheme in R6 :
MOTHER (MOTHER is a virtual class)
/ | \
/ …

lrnv
- 1,038
- 8
- 19
2
votes
1 answer
Accessing R6 class variable when variable name is not known advance?
Here's a simple code, which illustrates what I'd like to achieve:
require(R6)
cTest <- R6Class(
"CTest",
public = list(
a = 10, b=20, c=30,
printX = function(x) {
print(self[x])
}
)
) #"CTest"
myClass <- cTest$new();
for…

IVIM
- 2,167
- 1
- 15
- 41
2
votes
1 answer
Include R6 class object in R package
I am currently developing an R package and I want to include an object of class R6, which is basically an environment, so that users can easily use it (same way it works with datasets in a package).
I have an R6ClassConstructor Gridworld:
Gridworld…

needRhelp
- 2,948
- 2
- 24
- 48
2
votes
0 answers
Cleanup when `global.R` variables are deleted
Question
From the documentation it is clear, that variables in server.R have a different life span than the ones in global.R.
For cleanup operations in server, there is the session$onSessionEnded callback function. An example to use this can be…

Gregor de Cillia
- 7,397
- 1
- 26
- 43
2
votes
1 answer
In R, how can I check if two variables reference the same R6 object?
The identical() function seems to give the correct answer, but the documentation doesn't explicitly discuss object references. The closest note in the documentation is:
Checking equality for two large, complicated objects can take longer
if the…

cbailiss
- 1,304
- 11
- 21