inst/test_files/test_R6_2.R

Person2 <- R6Class("Person", public = list(
    x = 10,
   initialize = function(name, age) {
       private$name <- name
       private$age <- age
   },
   get_age = function() {
       # checks if public method can access private variable
       print(private$age)
       # checks if private method can access public variable
       print(private$get_age_plus_x())
   }
), private = list(
   age = JS_NULL,
   name = JS_NULL,
   get_age_plus_x = function() {
       return(private$age + self$x)
   }
))
elena <- Person2$new("Elena", 4)
elena$get_age()

Try the sketch package in your browser

Any scripts or data that you put into this service are public.

sketch documentation built on Oct. 23, 2022, 5:07 p.m.