R에서 S3와 R6로 배우는 Object-Oriented Programming
Richie Cotton
Data Evangelist at DataCamp



thing_factory <- R6Class(
"Thing"
)
child_thing_factory <- R6Class(
"ChildThing",
inherit = thing_factory
)
grand_child_thing_factory <- R6Class(
"GrandChildThing",
inherit = child_thing_factory
)
thing_factory <- R6Class( "Thing",public = list( do_something = function() { message("the parent do_something method") } ))
child_thing_factory <- R6Class( "ChildThing", inherit = thing_factory,public = list( do_something = function() { message("the child do_something method") } ))
grand_child_thing_factory <- R6Class( "GrandChildThing", inherit = child_thing_factory, public = list( do_something = function() { message("the grand-child do_something method")super$do_something()super$super$do_something()} ) )
a_grand_child_thing <- grand_child_thing_factory$new()a_grand_child_thing$do_something()
the grand-child do_something methodthe child do_something methodError in a_grand_child_thing$do_something(): attempt to apply non-function
child_thing_factory <- R6Class( "ChildThing", inherit = thing_factory, public = list( do_something = function() { message("the child do_something method") } ),active = list( super_ = function() super ))
grand_child_thing_factory <- R6Class( "GrandChildThing", inherit = child_thing_factory, public = list( do_something = function() { message("the grand-child do_something method")super$do_something()super$super_$do_something()} ) )
a_grand_child_thing <- grand_child_thing_factory$new()a_grand_child_thing$do_something()
the grand-child do_something method
the child do_something method
the parent do_something method
super_라는 active 바인딩을 사용하십시오super_는 super를 그대로 반환하면 됩니다R에서 S3와 R6로 배우는 Object-Oriented Programming