Skip to content

Format an expression as a tree

Source code

Description

Format an expression as a tree

Usage

<Expr>$meta$tree_format(return_as_string = FALSE)

Arguments

return_as_string Return the tree as a character vector? If FALSE (default), the tree is printed in the console.

Value

If return_as_string is TRUE, a character vector describing the tree.

If return_as_string is FALSE, prints the tree in the console but doesn’t return any value.

Examples

library(polars)

my_expr = (pl$col("foo") * pl$col("bar"))$sum()$over(pl$col("ham")) / 2
my_expr$meta$tree_format()
#>             0              1              2             3
#>    ┌───────────────────────────────────────────────────────────
#>    │
#>    │  ╭────────────╮
#>  0 │  │ binary: // │
#>    │  ╰─────┬┬─────╯
#>    │        ││
#>    │        │╰─────────────╮
#>    │        │              │
#>    │   ╭────┴─────╮    ╭───┴────╮
#>  1 │   │ lit(2.0) │    │ window │
#>    │   ╰──────────╯    ╰───┬┬───╯
#>    │                       ││
#>    │                       │╰─────────────╮
#>    │                       │              │
#>    │                  ╭────┴─────╮     ╭──┴──╮
#>  2 │                  │ col(ham) │     │ sum │
#>    │                  ╰──────────╯     ╰──┬──╯
#>    │                                      │
#>    │                                      │
#>    │                                      │
#>    │                                ╭─────┴─────╮
#>  3 │                                │ binary: * │
#>    │                                ╰─────┬┬────╯
#>    │                                      ││
#>    │                                      │╰────────────╮
#>    │                                      │             │
#>    │                                 ╭────┴─────╮  ╭────┴─────╮
#>  4 │                                 │ col(bar) │  │ col(foo) │
#>    │                                 ╰──────────╯  ╰──────────╯