Advertisement
Guest User

Untitled

a guest
Jun 25th, 2019
76
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.73 KB | None | 0 0
  1. if (!"package:R6" %in% search()) {
  2. library(R6)
  3. }
  4.  
  5.  
  6. # Class
  7.  
  8.  
  9. Game <- R6Class("Game",
  10.  
  11. public = list(
  12.  
  13. # Properties:
  14.  
  15. a = 0,
  16. b = 0,
  17. sum = 0,
  18.  
  19.  
  20. # Functions:
  21.  
  22. run = function() {
  23. part_1()
  24. part_2()
  25. part_3()
  26. },
  27.  
  28. part_1 = function() {
  29. self$a = 10
  30. return(self$a)
  31. },
  32.  
  33. part_2 = function() {
  34. self$b = 20
  35. return(self$b)
  36. },
  37.  
  38. part_3 = function() {
  39. self$sum = self$a + self$b
  40. return(self$sum)
  41. }
  42.  
  43. )
  44.  
  45. )
  46. # Instantiate an object base on a class.
  47. game <- Game$new()
  48.  
  49. # Run function that runs through all other functions.
  50. game$run()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement