Session Ready
Exercise

Close the Door

Methods for an R6 object can access its private fields by using the private$ prefix.

thing_factory <- R6Class(
  "Thing",
  private = list(
    a_field = "a value",
    another_field = 123
  ),
  public = list(
    do_something = function(x, y, z) {
      # Access the private fields
      paste(
        private$a_field, 
        private$another_field
      )
    }
  )
)
Instructions
100 XP

A microwave oven factory has been partially defined for you. It has been updated to include a private door_is_open field, and a public open_door method.

  • Add a public method named close_door() to close the microwave door.
    • The method should take no arguments.
    • In the body of the function, set the door_is_open field to FALSE.