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
8
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
  • 133
  • 6
7
votes
2 answers

How to include R6 objects to share data across modules in golem Shiny app

I’m trying to create a Shiny app using golem for the first time. golem structures Shiny apps with modules to help keep large Shiny apps modularized. However, modules don’t communicate with each other by default. I’d like to share data across…
itpetersen
  • 1,475
  • 3
  • 13
  • 32
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.
  • 7,018
  • 6
  • 44
  • 69
6
votes
3 answers

Testing private methods in R6 classes in R

I am currently using R6 classes in a project. I would like to write unit tests that also test the functionality of private methods that I am using (preferably by not going through the more complicated public methods that are using these private…
Holger Hoefling
  • 388
  • 3
  • 13
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
  • 16,384
  • 4
  • 79
  • 160
5
votes
1 answer

creating Rd documentation files for R6 classes not in a package

I am trying to create the documentation of a few scripts that have some R6 classes in it. As an example I use the R6Class named "Person" from here: https://www.tidyverse.org/blog/2019/11/roxygen2-7-0-0/ I am using this function…
Bolle
  • 322
  • 2
  • 11
5
votes
1 answer

Use "with" with an R6 object

I'm trying to use a construct such as "with" to allow easier (lazier ?) manipulation of an R6 object. Consider the following (minimal) example: library(R6) ToyClass<-R6Class(classname = "ToyClass", public = list( …
jfmoyen
  • 495
  • 2
  • 11
5
votes
2 answers

define a bracket (`[`) operator on an R6 class

Here's what does not work: library(R6) Foo = R6::R6Class( 'Foo', public = list( X = NULL, metadata = NULL, initialize = function(X, metadata){ self$X = X self$metadata = metadata }, …
zkurtz
  • 3,230
  • 7
  • 28
  • 64
5
votes
2 answers

Defining methods that call other methods outside of R6 objects

When using R6 classes, what is the proper way to define methods outside of the class that call other methods? Consider the following example, where the function func might dispatch to another function if it is being used interactively. But, if it…
Rorschach
  • 31,301
  • 5
  • 78
  • 129
5
votes
1 answer

Class Variables with R6

I was curious if there was a way to create class variables for R6 classes within the definition of the class? I read through the Introduction to R6 classes vignette but didn't find any mention of class variables. I am able to create class variables…
jeromefroe
  • 1,345
  • 12
  • 19
4
votes
1 answer

R: Use active binding in object generator to conditionally add new class to R6 objects

I have a simple R6 object generator: thing <- R6Class("youngThing", private = list( ..age = 0), active = list( age = function(){ private$..age <-…
jayb
  • 555
  • 3
  • 15
4
votes
1 answer

How to create a new type which plays well inside data.frame?

I guess there are several ways to do this. Hence, the answers to this question could be subjective, if not opiniated. So I will try to narrow the problem, and give you the details of what I have already done. Context I am working with the R6 package…
pietrodito
  • 1,783
  • 15
  • 24
4
votes
1 answer

How to use `foreach` and `%dopar%` with an `R6` class in R?

I ran into an issue trying to use %dopar% and foreach() together with an R6 class. Searching around, I could only find two resources related to this, an unanswered SO question and an open GitHub issue on the R6 repository. In one comment (i.e.,…
Mihai
  • 2,807
  • 4
  • 28
  • 53
4
votes
0 answers

R: Make a R6 class object iterable

In Python we can make a new class iterable by adding __iter__. Can we do something like this in R with R6 class (or any class)? For example: my_list_class <- R6Class("my_list_class", public = list( elem = list(), initialize =…
morningfin
  • 329
  • 2
  • 10
4
votes
1 answer

Loading object into global environment in R Package using .onLoad()

I’m working on an R Package in which I need to manage the state of various objects over time. Conceptually, when the package loads (.onLoad), it checks for the state object in cache and if it doesn’t exist, a new instance is created, saved to cache,…
John
  • 149
  • 3
  • 14
1
2
3
12 13