Search code examples
roopmethodsprivater6

Creating private values from other private values in R6


Is there any way to use a private value in order to create another private value inside R6Class()? I am getting errors.

obj <- R6Class(
  "abc",
  private = list(
    a = 2,
    b = 2*private$a
  )
)

Error in all_named(private) : object 'private' not found

I have also tried to create b with b = 2 * a, but it is still impossible. How should I go about it?

Thank you


Solution

  • obj <- R6Class(
       "abc",
      private = list(
        a = 2,
        b = function() 2*self$a
       )
    )