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
0
votes
1 answer
Error populating class variable in R6 - cannot access class variable
Here is my example:
library(R6)
SharedVar <- R6Class("SharedVar",
public = list(x= NULL)
)
MainClass <- R6Class("MainClass",
public = list(
name = NULL,
…

user1700890
- 7,144
- 18
- 87
- 183
0
votes
1 answer
Inside R6 class definition: 'object not found' (or: how to define 'local' objects in R6 classes)
I want to define an R6 class that sets up, updates and closes a progress bar. For these 3 tasks, I have 3 functions. The first, setup_progressbar(), calls R's txtProgressbar() which returns an object (say, pb) which needs to be passed on to the…

Marius Hofert
- 6,546
- 10
- 48
- 102
0
votes
1 answer
Initialize R6 class with an instance of Class and return the same Class
Given an R6 class Class1 with its initialize function, I would like to be able to pass an instance of the same class and return it directly.
Something like this:
if("Class1" %in% class(x)) x
else Class1$new(x)
But inside the initialize function of…

Duccio A
- 1,402
- 13
- 27
0
votes
1 answer
Unable to access object inside function using an external function R6
I have a R6 class with code like this
# Cutting out lots of code and only putting in relevant lines
public(
function1 <- function(){
var <- xyz$abc
},
function2 <- function(){
xyz <- blah blah
z <- function1()
}
)
When…

user123231322
- 65
- 5
0
votes
1 answer
Calling R6 method dynamically where method name is stored in string variable
How do you call a R6 method dynamically i.e the method name is held as a string variable:
Test <- R6Class("Test",
public = list(
char_to_upper = function(var) { toupper(var) }
))
# create test object
test_obj <- Test$new()
# method name…

Samir Malik
- 1
- 1
0
votes
1 answer
Can you use helper functions inside R6 objects?
I'm trying to avoid repetition inside an R6 object. There are calculated/derived values that must be updated each time one of the inputs is updated.
The Cube object below demonstrates the problem. If I update any of width, height or depth, it…

ricardo
- 8,195
- 7
- 47
- 69
0
votes
1 answer
'testthat', how should I interpret this failure?
I want to use 'testthat' to add tests to my package.
This is my test-file:
library(RBaseX)
test_that("Credentials are accepted", {
skip_unless_socket_available()
expect_error(BasexClient$new("localhost", 1984L, username = "admin", password =…

Ben Engbers
- 433
- 3
- 12
0
votes
0 answers
Automatically remove R6 object
I have created a bank account class with the R6 package . It has a balance that is private (not accessible after generation) and methods to withdraw and deposit a certain amount as well as a print method. (Hadley Wickham 14.3.3)
BankAccount <-…

umbecdl
- 21
- 3
0
votes
1 answer
[R6]Error in as.vector(x, "symbol") : cannot coerce type 'environment' to vector of type 'symbol'
I use my R6 object and funcion in the following code
Test = R6Class(
"test",
public = list(
y_name = NA,
initialize = function(y_name){
self$y_name = y_name
}
)
)
someAnalysis = function(tbl, y_name = "y_name", y = "a",…

RRR
- 133
- 7
0
votes
1 answer
R - translating Python class to R's R6 class - unique names error
I am working on translating the word search algorithm implemented in both Julia (for the main code -- https://rosettacode.org/wiki/Word_search#Julia) and Python (for the creation of the class for Grid --…

iembry
- 962
- 1
- 7
- 23
0
votes
0 answers
Import magrittr in private R6 methods in a package
Last year I have written a BaseX client in R (https://github.com/BaseXdb/basex/tree/master/basex-api/src/main/r) and now I am trying to build a package for this driver.
The driver is built, using the R6 system. I added these directives to…

Ben Engbers
- 433
- 3
- 12
0
votes
0 answers
OpenAPI generated R enum is faulty & seems to contain nothing
I am attempting to create R code via OpenAPI Generator which has worked fine generally; now I have realized that there is in fact a problem with enums. When attempting to source() these classes, I get an Error "bad value", which, on inspection makes…

Yato
- 64
- 8
0
votes
0 answers
Change property value during run of instantiated object
I am attempting to change the value of a property, throughout the course of running an instantiated object. This is part of a download mechanism where value 20 is set to perform a first download of data for 20 lines, the rest of downloads will be…

Toolbox
- 2,333
- 12
- 26
0
votes
2 answers
How to import class data prior to instantiate the class
Assuming that the class and instantiation of class are held in 2 separate files, how would you import the class data prior to instantiate the class?
Below code works fine if held in one same file, but I suspect that as soon as the code base starts…

Toolbox
- 2,333
- 12
- 26
0
votes
0 answers
Testing R6 classes
Are there any frameworks out there for testing object-oriented R code, say R6 classes, that is comparable to JUnit?
As a software engineer coming from the Java world, I find testing R code surprisingly cumbersome when compared to using JUnit for…

Endre
- 690
- 8
- 15