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

181 questions
4
votes
1 answer

How to profile R6 class functions?

R6 class functions are anonymous so profiling information is lost. For example: library(R6) library(proftools) Test <- R6Class("Test", public = list( fn = function() pause(0.3) ) ) obj <- Test$new() # #…
Epimetheus
  • 1,119
  • 1
  • 10
  • 19
4
votes
1 answer

Inconsistency of S4 dispatch behavior for R6 classes

Actual questions Shouldn't the fact that R6 classes inherit from (informal S3) class R6 allow the definition of S4 methods for signature arguments of that very class? As this is - AFAICT - not the case, what would be a workaround that is in line…
Rappster
  • 12,762
  • 7
  • 71
  • 120
4
votes
1 answer

xts assignment by reference

Let's have: library(R6); library(data.table); library(xts) Portfolio <- R6Class("Portfolio", public = list(name="character", prices = NA, initialize =…
Daniel Krizian
  • 4,586
  • 4
  • 38
  • 75
3
votes
0 answers

When are R6 objects more efficient than traditional lists?

I am working on an R package where performance is important (there will be many iterations due to bootstrapping), and planned to use the R6 library since an object-oriented approach made most sense in my head. The alternative seems to be…
taffel
  • 133
  • 1
  • 5
3
votes
0 answers

Inheriting Roxygen documentation from R6 methods

How to inherit roxygen documentation from an R6 method? The following code (slightly changed Roxygen R6 documentation example) #' R6 Class representing a person #' #' A person has a name and a hair color. Person <- R6::R6Class("Person", …
Martin
  • 31
  • 1
3
votes
2 answers

How to import an R6 class into a package?

I would like to use functions in my personal package built on top of an R6 class called ms_team defined inside of the Microsoft365R package. Right now these functions all fail because even though I import the functions I need, when I try to call one…
wdkrnls
  • 4,548
  • 7
  • 36
  • 64
3
votes
2 answers

Efficient object creation with R6

I want to create a group of R6 objects from the following example constructor: myClass <- R6Class("myClass", public = list( height = NA, initialize = function() { …
jayb
  • 555
  • 3
  • 15
3
votes
1 answer

Replacement function as R6 class member function

I have been playing around with R6 ab bit and tried to implement a replacement function (similar in spirit to base::`diag<-`()). I wasn't hugely surprised to learn that the following does not work library(R6) r6_class <- R6Class("r6_class", …
nbenn
  • 591
  • 4
  • 12
3
votes
1 answer

How to call a function in the R6 parent class, where the parent function relies on other overridden helper functions

I am trying to create a class in R6 which inherits a function from its parent class. However, that function relies on other 'helper' functions which are overwritten in the child class. When I call the parent function, I want it to use the helper…
ClownsENT
  • 155
  • 1
  • 8
3
votes
1 answer

In R how to sort array of R6 objects

How can I sort/order R6 objects based on an own function value or a compare function value? I have made up a little example with rectangles that I would like to sort by their area: library('R6') Rectangle <- R6Class( "Rectangle", public =…
Morten Grum
  • 962
  • 1
  • 10
  • 25
3
votes
2 answers

R6 — Why does active binding print twice the content when using the print function?

I'm creating an active binding in an R6 class to print a private element. When I'm calling print(private$privMail), the result is printed twice but only on private elements, not on public. If I'm not using print, no problem. Here's a reprex :…
Colin FAY
  • 4,849
  • 1
  • 12
  • 29
3
votes
2 answers

Documenting R6 class methods with Roxygen2

I'm writing a package with an R6 class that has several methods. I would like to be able to generate documentation for both, class and methods. For the below example, I would like to be able to access the docs with ?Person for the class and…
user1981275
  • 13,002
  • 8
  • 72
  • 101
3
votes
2 answers

Using R6, how do I find classes and objects that inherit from some superclass?

Suppose I have: Foo <- R6::R6Class("Foo") Bar1 <- R6::R6Class("Bar1", inherit = "Foo") Bar2 <- R6::R6Class("Bar2", inherit = "Foo") f <- Foo$new() A. Can I do something like R6::findChildren("Foo") [1] "Bar1" "Bar2" (I think this the same as R,…
Jack Tanner
  • 934
  • 1
  • 8
  • 24
3
votes
2 answers

updating method definitions in R6 object instance

How can I update the method definition of an R6 class instance? S3 uses the current method defintion, as I would expect. With R5 (Reference Classes) I can use myInstance=myInstance$copy(). With R6 I tried myInstance = myInstance$clone() but…
thomasw
  • 129
  • 8
2
votes
0 answers

R6 array member, copy on update

the following code require(R6) Array <- R6Class( "Array", public=list( x=matrix(0,0,0), initialize=function(a,b,c){ self$x <- matrix(a,b,c) }, assign=function(z){ self$x[1,1] <- z invisible(self) } ) ) x…
user1407220
  • 353
  • 1
  • 12
1 2
3
12 13