block by timelyportfolio 3d82ac671c58de5117fe

data.tree / R6 + pipeR experiment

I don’t think combining pipeR + data.tree makes a lot of sense, but that doesn’t mean I won’t try. If nothing else, I think it is a great example why pipeR is my favorite piper.

Links to R packages mentioned

pipeR
data.tree

Code Without Assignment

# data.tree example but using pipeR
#### readme example from data.tree vignette ####
#### https://github.com/gluc/data.tree/blob/master/vignettes/data.tree.Rmd ####
#### pipe with data.tree with R6 ####

library(pipeR)
library(data.tree)

acme <- Node$new("Acme Inc.") %>>%
  (~
     .$AddChild("Accounting")  %>>%
      (~{
        .$AddChild("New Software")
        .$AddChild("New Accounting Standards")
      })
  ) %>>%
  (~
     .$AddChild("Research") %>>%
      (~{
        .$AddChild("New Product Line")
        .$AddChild("New Labs")
      })
  ) %>>%
  (~
     .$AddChild("IT") %>>%
      (~{
        .$AddChild("Outsource")
        .$AddChild("Go agile")
        .$AddChild("Switch to R")
      })
  )

print(acme)

Code With Assignment

#### pipe with data.tree with R6 ####

library(pipeR)
library(data.tree)

acme <- Node$new("Acme Inc.") %>>%
  (~
     '<<-'( accounting , .$AddChild("Accounting") )  %>>%
      (~{
        '<<-'( software, .$AddChild("New Software") )
        '<<-'( standards, .$AddChild("New Accounting Standards") )
      })
  ) %>>%
  (~
     '<<-'( research, .$AddChild("Research") ) %>>%
      (~{
        '<<-'( newProductLine, .$AddChild("New Product Line") )
        '<<-'( newLabs, .$AddChild("New Labs") )
      })
  ) %>>%
  (~
     '<<-'( it, .$AddChild("IT") ) %>>%
      (~{
        '<<-'( outsource, .$AddChild("Outsource") )
        '<<-'( agile, .$AddChild("Go agile") )
        '<<-'( goToR, .$AddChild("Switch to R") )
      })
  )

print(acme)

code.R