From the "Introduction to R6 classes" vignette (emphasis mine):
self
Inside methods of the class, self
refers to the object. Public members of the object (all you’ve seen so far) are accessed with self$x
private
Whereas public members are accessed with self
, like self$add()
, private members are accessed with private
, like private$queue
.
So, even if you can access private methods through self
, you should do it through private
. Don't rely on behavior which may go away, seeing as how the documentation says it shouldn't work like that.
That said, I can't access private methods using self
:
library(R6)
bar <- R6Class("bar",
private = list(
foo = function() {
message("just foo it")
}
),
public = list(
call_self = function() {
self$foo()
},
call_private = function() {
private$foo()
}
)
)
b <- bar$new()
b$call_private()
# just foo it
b$call_self()
# Error in b$call_self() : attempt to apply non-function