Closed guolinke closed 7 years ago
example code:
test <- R6Class("Test", public = list( a = 10, fun = function(other){ other$c }, setc = function(c){ private$c <- c }, getc = function(){ private$c } ), private = list( c = 20 ) ) x <- test$new() y <- test$new() y$setc(100) y$getc() x$fun(y)
for x$fun(y) it should return 100, but it is NULL now.
x$fun(y)
100
NULL
Is there any way that I can access private member from other instances of the same class?
Sorry, there isn't a way to do that. You could access any R6 object's private fields with x$.__enclos_env__$private, but that's a bit of hack.
x$.__enclos_env__$private
example code:
for
x$fun(y)
it should return100
, but it isNULL
now.Is there any way that I can access private member from other instances of the same class?