Build a diagram of a optree pipeline.
op_diagram(optree, ..., merge_tables = FALSE, show_table_columns = TRUE)
operation tree pipeline (or list of such).
force other argument to be by name.
logical, if TRUE merge all same table references into one node. rel_op nodes that declare a materialize_as name will be cross-linked.
logical, if TRUE show table columns.
character DiagrammeR::grViz() ready text.
d <- mk_td('d',
columns = qc(AUC, R2))
optree <- d %.>%
extend(., v %:=% ifelse(AUC>0.5, R2, 1.0)) %.>%
quantile_node(.) %.>%
natural_join(., d, jointype = "LEFT", by = "AUC") %.>%
orderby(., "AUC")
cat(format(optree))
#> mk_td("d", c(
#> "AUC",
#> "R2")) %.>%
#> extend(.,
#> v := ifelse(AUC > 0.5, R2, 1)) %.>%
#> non_sql_node(., quantile_node(.)) %.>%
#> natural_join(.,
#> mk_td("d", c(
#> "AUC",
#> "R2")),
#> jointype = "LEFT", by = c('AUC')) %.>%
#> order_rows(.,
#> c('AUC'),
#> reverse = c(),
#> limit = NULL)
cat(op_diagram(optree))
#>
#> digraph rquery_optree {
#> graph [ layout = dot, rankdir = TB, overlap = prism, compound = true, nodesep = .5, ranksep = .25]
#> edge [decorate = true, arrowhead = normal]
#> node [style=filled, fillcolor=lightgrey]
#>
#> node_1 [ shape = 'folder' , fillcolor = 'chartreuse3' , label = 'mk_td(d, c(\l AUC,\l R2))\l']
#>
#> node_2 [ shape = 'box' , fillcolor = 'khaki3' , label = 'extend(.,\l v := ifelse(AUC > 0.5, R2, 1))\l']
#>
#> node_3 [ shape = 'box' , fillcolor = 'khaki3' , label = 'non_sql_node(., quantile_node(.))\l']
#>
#> node_4 [ shape = 'folder' , fillcolor = 'chartreuse3' , label = 'mk_td(d, c(\l AUC,\l R2))\l']
#>
#> node_5 [ shape = 'box' , fillcolor = 'khaki3' , label = 'natural_join(.1, .2, j= LEFT, by= AUC)\l']
#>
#> node_6 [ shape = 'box' , fillcolor = 'khaki3' , label = 'order_rows(.,\l c(AUC),\l reverse = c(),\l limit = NULL)\l']
#> node_1 -> node_2 [ label = '.']
#> node_2 -> node_3 [ label = '.']
#> node_3 -> node_5 [ label = '.1']
#> node_4 -> node_5 [ label = '.2']
#> node_5 -> node_6 [ label = '.']
#> }
# if(requireNamespace("DiagrammeR", quietly = TRUE)) {
# optree %.>%
# op_diagram(., merge_tables = TRUE) %.>%
# DiagrammeR::grViz(.) %.>%
# print(.)
# # # or to render to png
# # optree %.>%
# # op_diagram(., merge_tables = TRUE) %.>%
# # DiagrammeR::DiagrammeR(diagram = ., type = "grViz") %.>%
# # DiagrammeRsvg::export_svg(.) %.>%
# # charToRaw(.) %.>%
# # rsvg::rsvg_png(., file = "diagram1.png")
# }