Questions tagged [r6]

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

145 questions
21
votes
2 answers

Wrapping shiny modules in R6 classes

I am currently wrapping shiny modules in R6 classes and wanted to hear some opinions about this design. Basically, I am interested in a clean approach (readable code) and want the classes to allow nesting (see the nesting modules section here). The…
Gregor de Cillia
  • 5,775
  • 1
  • 17
  • 33
21
votes
2 answers

Simultaneously access environment from two R sessions

Is it technically possible in R? I would like to run a shiny instance with prepared R6 object (environment class), use its methods - mostly read only. While at the same time as shiny app running I would like to call other methods of my R6 -…
jangorecki
  • 14,077
  • 3
  • 57
  • 137
18
votes
2 answers

Sub-assign by reference on vector in R

Can I use sub-assign by reference on atomic vectors somehow? Of course without wrapping it in 1 column data.table to use :=. library(data.table) N <- 5e7 x <- sample(letters, N, TRUE) X <- data.table(x = x) upd_i <- sample(N, 1L,…
jangorecki
  • 14,077
  • 3
  • 57
  • 137
17
votes
2 answers

Documenting R6 classes and methods within R package in RStudio

I am struggling with the documentation of an R6 class and its methods. My goal is to get the autocompletion in RStudio for the methods. At the moment, I only get the name of the method but no the help information I normally get using roxygen2…
drmariod
  • 9,470
  • 8
  • 48
  • 96
14
votes
1 answer

Proper way to implement S3 dispatch on R6 classes

I have an R6 class and I want to add an S3 method for it. The documentation I found mentioned briefly that in order to use S3 dispatch on R6 you must have class = TRUE, but I couldn't find an example of how it should be done. I did see empirically…
DeanAttali
  • 21,721
  • 9
  • 77
  • 106
12
votes
2 answers

Multiple inheritance for R6 classes

Actual question What are my options to workaround the fact that R6 does not support multiple inheritance? Disclaimer I know that R is primarily a functional language. However, it does also have very powerful object-orientation built in. Plus: I…
Rappster
  • 11,680
  • 7
  • 58
  • 113
12
votes
2 answers

Static methods in R6 classes

Is there a way to add static methods to R6 classes? For example, a function that can be called like MyClass$method() Instead of myinstance <- MyClass$new() myinstance$method()
Abiel
  • 4,595
  • 6
  • 47
  • 66
10
votes
1 answer

Change initialize method in subclass of an R6 class

Let's say I have a R6 class Person: library(R6) Person <- R6Class("Person", public = list(name = NA, hair = NA, initialize = function(name, hair) { self$name <- name self$hair <- hair …
Thomas Neitmann
  • 1,742
  • 1
  • 11
  • 24
10
votes
1 answer

parLapply within R6 classes

I'm looking to use parLapply() on windows within an R6 object and noticed (that in at least some cases) that I do not need to export the R6 functions or data to the nodes. Here is an example where I can access private methods within…
chandler
  • 616
  • 7
  • 13
9
votes
1 answer

R, R6 Operator Overloading

Consider the following: A = R6::R6Class("ClassA") B = R6::R6Class("ClassB") `+.ClassA` = function(o1,o2) o1 #Trivial Example, Usually do something `+.ClassB` = function(o1,o2) o1 #Trivial Example, Usually do something a = A$new() b = B$new() a +…
Nicholas Hamilton
  • 8,709
  • 5
  • 47
  • 75
9
votes
1 answer

How do I tell an R6 class what to do with square brackets?

I have an R6 class that has as an attribute a data.table. Let's say it looks like this: library(R6) library(data.table) foo <- R6Class( classname = 'foo', public = list( dt = NA, initialize = function(dt) { self$dt <- dt } …
crf
  • 1,371
  • 3
  • 10
  • 21
8
votes
2 answers

In object-oriented R programming, what is an "active binding"?

In object-oriented R programming (especially Winston Chang's R6 package), what is an active binding?
histelheim
  • 4,404
  • 5
  • 29
  • 58
7
votes
1 answer

R: how to define multiple constructors for an R6 class?

I am currently working on a project where I need to build an R6 class in R that can be initialized in more than one way. I am wondering what the best way is to go about it. Is it possible to overload the $new() function? Or do I need to define a…
Berk U.
  • 6,488
  • 5
  • 40
  • 65
7
votes
3 answers

dynamically add function to r6 class instance

I'm trying to forget refclasses (R5) and move to R6 but there is a problem with dynamic code. I would add a new function and it works in R5: clsTrn <- setRefClass("clsTrn", fields = list(x = "numeric"), methods = list( add_function =…
Daniel
  • 123
  • 6
6
votes
2 answers

R parallel: rbind parallely into separate data.frames

The below code produces different results on Windows and Ubuntu platforms. I understand it is because of the different methods of handling parallel processing. Summarizing: I cannot insert / rbind data on Linux parallely (mclapply, mcmapply) while…
jangorecki
  • 14,077
  • 3
  • 57
  • 137
1
2 3
9 10