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
1
vote
2 answers
Is it possible to change the value of R6 function ? (Good style OOP programming?)
I'm coming from C++ background, trying to make use of it for R OOP programming with R6 package.
Consider the following typical situation when writing a large OOP code. -
You have a class, in which you have several (possibly many) functions, each of…

IVIM
- 2,167
- 1
- 15
- 41
1
vote
1 answer
how to modify a list of R6class objects by reference?
See this short example:
library(R6)
library(pryr)
Person <- R6Class("Person", public = list(name = NA, hair = NA, initialize = function(name,
hair) {
if (!missing(name)) self$name <- name
if (!missing(hair)) self$hair <- hair
}, set_hair =…

mt1022
- 16,834
- 5
- 48
- 71
1
vote
0 answers
R tensorflow computation in an R6 class method returns error
In R I have an R6 class with a predict method. When the predict method is called, it should run the tensorflow computation, here multiply inputs and weights.
This is the code:
NeuralNetworkTensorflow = R6::R6Class("NeuralNetworkTensorflow",
…

needRhelp
- 2,948
- 2
- 24
- 48
1
vote
1 answer
R6 and Magrittr
I have an R6 class, which contains a family of helper functions for conducting routine checks. These functions exist in the public list, usually take a single argument, conduct some checks on the value passed to the single argument, and if nothing…

Nicholas Hamilton
- 10,044
- 6
- 57
- 88
1
vote
1 answer
Enforce Return Type in Function
Using R6, I would like to enforce that a method returns a particular data-type, Is this possible?
For Instance, consider the following:
A = R6::R6Class("ClassA",
public=list(
getx = function() as.integer(1)
)
)
B =…

Nicholas Hamilton
- 10,044
- 6
- 57
- 88
1
vote
1 answer
R, R6, Formals for Public Method
How can I get the formals for a method definition in an R6 class definition?
A = R6Class("MyClass",inherit=NULL,
public = list(
fun = function(a,b,c){
# Do Something
}
)
)
So for example, in the above, I would…

Nicholas Hamilton
- 10,044
- 6
- 57
- 88
1
vote
1 answer
Using a closure to generate an R6 binding
I'm using active bindings in an R6 class to check values before assignment to fields. I thought I could use a closure to generate the bindings as below, but this doesn't work.
The binding isn't evaluated in the way I expect (at all?) because the…

effel
- 1,421
- 1
- 9
- 17
1
vote
1 answer
Formals within R6Class
I'm trying to get the formals() of a function within an R6Class. But this does not seem to work. I think there might be a problem with the environments.
Test <- R6Class(
"Test",
public = list(
foo = function(x){
x
},
…

Fabian Gehring
- 1,133
- 9
- 24
1
vote
0 answers
Are R6 objects compatible with parallels package?
I'm thinking about leaving the S4 approach of R on OOP alone and I want to try using OOP with the newer R6 Package.
Now I want to know: Are the objects I am building using the package R6 compatible with the "parallel" package?
Thank you all.

Bmb58
- 155
- 2
- 9
0
votes
1 answer
R Shiny: Update a R6 Object on different actionButtons
I am trying to build a shiny update that allows the user to update a R6 Class object by clicking different actionButtons, as shown in the example below.
I also looked into different options such as using reactiveValues etc, but I cannot get it to…

lukp
- 7
- 2
0
votes
1 answer
Recreate reactiveValues in shiny without reactiveness (but same scoping behaviour)
I have a shiny app split into multiple modules. To pass data between the modules I use reactiveVal(ues). These can be passed to functions and modified from within the other functions.
I would like to create a similar object, but without all the…

Elias
- 88
- 5
0
votes
1 answer
R6 inherit does not carry information of the inherited class when used in a function
See example code:
myfunc <- function(inherit) {
return(R6::R6Class("Derived", inherit = inherit))
}
Base <- R6::R6Class("Base")
Derived <- R6::R6Class("Derived", inherit = Base)
Derived2 <- myfunc(Base)
print(Derived)
print(Derived2)
Despite…

Stefano Borini
- 138,652
- 96
- 297
- 431
0
votes
1 answer
Assign multiple object and functions in a list by loop or apply family
I am creating a list that contained multiple objects and functions.
Each object and function had a similar naming and pattern.
Refer below as the example. In the real case, we have lots more assignments.
lst <- list()
lst$ObjectA <-…

Howard
- 61
- 4
0
votes
0 answers
How to convert function definition character string into a function for the use within R6 class?
This question relates to the previous one: How to change public R6 class method from outside of the class?. (the solution to which is posted here: How to change public R6 class method from outside of the class?)
In that question, i needed to modify…

IVIM
- 2,167
- 1
- 15
- 41
0
votes
1 answer
How to change public R6 class method from outside of the class?
I'd like to be able to redefine a public method in my R6 class (so that it changes according to the type of data that the class holds) - like below
library(R6)
Simple <- R6Class(
"Simple",
public = list(
dt = mtcars,
my.print = function…

IVIM
- 2,167
- 1
- 15
- 41