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
2
votes
1 answer

R, R6, Get Full Class Name from R6Generator Object

In R6, How can I get the full list of class inheritances, without creating instances of the generator objects? Consider the following: A = R6::R6Class("Base",NULL) B = R6::R6Class("Top",inherit = A) class(B) #Returns…
Nicholas Hamilton
  • 10,044
  • 6
  • 57
  • 88
2
votes
1 answer

"User" constructor for R6 class in R

I am learning how to use R6 classes (and in general R OO). In this tutorial I found an interesting way of presenting constructors. In section 6.3 a different kind of constructor is defined, returning a class instance with "new" called inside the…
mic
  • 927
  • 8
  • 17
2
votes
1 answer

Creating dynamically methods in R6Class, magic of print(ls.str())

In R, I wanted to create a class (R6Class) that when calling initialize creates few dynamic methods (the number of methods and its names depends on parameters in initialize). But I get into strange problem with environments. Here is a simplified…
Bartek
  • 173
  • 1
  • 9
2
votes
1 answer

Registering S4 equivalents of R6 classes while preserving inheritance

Actual question How can I turn a bunch of R6 classes that inherit from each other into S4 classes while preserving the inheritance structure when all classes need to live in a package's namespace (as opposed to in GlobalEnv)? Details Everything…
Rappster
  • 12,762
  • 7
  • 71
  • 120
1
vote
1 answer

How to loop through subclasses within an R6 class

I'm new to the R6 classes and i'm starting to get the hang of things. However, i'm currently nesting classes and i want to loop through a list of specific nested classes. So, as shown in the example below, some of the elements of a Person class are…
Greacus
  • 35
  • 5
1
vote
1 answer

Allow user of R6 class to provide function which access `self`

Goal I want to tweak the following R6 class such that calc is not hard coded but can be provided by the user. Hard Coded library(R6) A <- R6Class("A", public = list( run = function(x) { private$calc(x) …
thothal
  • 16,690
  • 3
  • 36
  • 71
1
vote
2 answers

How can I namespace R6 classes in the R Language?

Longtime OOP developer here spinning up on R and R6. I'm used to having namespaces to hold the classes (e.g., Geom::Point, Vital::BloodPressure). I haven't found a way to do that in R. I'm not building a package but I'm not against it if that is the…
1
vote
1 answer

Can we get R6 class name from inside the class?

I need to get the name of the R6 class variable from inside the class. Can I do that? - like in example below: Simple <- R6Class( "Simple", public = list( myname = NA, dt =…
IVIM
  • 2,167
  • 1
  • 15
  • 41
1
vote
0 answers

Removing duplicate examples when documenting R6 with roxygen2

I am writing a package with an R6 class and several methods. When I use the @examples tag to conotatea method, the examples test is displayed twice in the output. #' R6 Class Representing a Person #' #' @description #' A person has a name and a hair…
1
vote
0 answers

How can I define a reference to a public field of an R6 class in Rcpp?

I am struggling with modifying elements of R environments in-place using Rcpp. More specifically, I would like to define variables pointing to elements of an R environment to ease working with public fields of an R6 class. Consider the following…
jack
  • 73
  • 1
  • 7
1
vote
0 answers

R6 classes, cloning, and a simple way of modifying the elements of the nested R6 object

I am developing a structure of R6 classes. The idea is to have a big R6 class collecting many small objects of other R6 class types. The big object is the input to a function. The point is that I would like to make it simple for users to modify the…
Tomasz
  • 78
  • 5
1
vote
1 answer

Shiny app modules: How to pass variables defined in the Server as arguments of functions in the UI?

i am using R6 to pass variables across and along the main server and server modules, following Jiwan Heo's approach as described in his article. Using a simplified example (without graph to minimise code length) of the mentioned article, this…
trevi
  • 589
  • 1
  • 6
  • 11
1
vote
1 answer

How to correctly write class methods in R6 and chain them

I need to create my own class object that takes a dataframe and has methods 'get_data' to choose dataframe, 'select' to select columns by their names and 'filter' to filter rows with certain values. Select and filter are a kind of similar to dplyr,…
A_K
  • 89
  • 6
1
vote
1 answer

Bringing subtotals upfront in pivottabler::qpvt

Wondering how to bring subtotals upfront (First row and/or first column) in pivottabler::qpvt. library(pivottabler) qpvt( dataFrame = bhmtrains , rows = c("=", "TOC") , columns = c("TrainCategory", "PowerType") …
MYaseen208
  • 22,666
  • 37
  • 165
  • 309
1
vote
1 answer

How to check if instance of `R6` class is present in a vector of class instances

I am looking for a way to check if a given instance of R6 class is present in a vector of R6 class instances. library(R6) # define a class Person <- R6Class("Person", list( name = NULL, initialize = function(name) self$name <- name )) # create…
Indrajeet Patil
  • 4,673
  • 2
  • 20
  • 51