Intro Thoughts

Status Quo

library(tidyverse)


Adder <- ggproto("Adder",
  out = 0,
  add = function(self, n) {
    self$out <- self$out + n
    self$out
  }
 )

is.ggproto(Adder)
#> [1] TRUE

Adder$add(3)
Adder$add(5)

Doubler <- ggproto("Doubler", 
                   Adder,
                   add = function(self, n) {
                     ggproto_parent(Adder, self)$add(n = n ^ 2)
                     }
                   )

Doubler$out
Doubler$add(10)

Experiment

Grouper <- ggproto("Grouper",
  out = Titanic %>% data.frame(),
  grouprows = function(self, group) {
    self$out <- group_by(self$out, {{group}}, .drop = F)
    self$out
  }
 )

GrouperCols <- ggproto("GrouperCols", 
                   Adder,
                   add = function(self, n) {
                     ggproto_parent(Adder, self)$out(group_by({{col}}))
                     }
                   )

GrouperRows$grouprows(Sex) |> GrouperCols$groupcols(Survived)


# 
# GrouperCols <- ggproto("GrouperCols", GrouperRows,
#   groupcols = function(self, cols) {
#     ggproto_parent(GrouperRows, self)$grouprows(group_by({{cols}}))
#   }
# )
# 
# 
# GrouperCols$groupcows(Survived)

Closing remarks, Other Relevant Work, Caveats