tree | R Documentation |
A cleaner and easier to read replacement for str
for nested list-like
objects
tree( x, ..., index_unnamed = FALSE, max_depth = 10L, max_length = 1000L, show_environments = TRUE, hide_scalar_types = TRUE, val_printer = crayon::blue, class_printer = crayon::silver, show_attributes = FALSE, remove_newlines = TRUE, tree_chars = box_chars() )
x |
A tree like object (list, etc.) |
... |
Ignored (used to force use of names) |
index_unnamed |
Should children of containers without names have indices used as stand-in? |
max_depth |
How far down the tree structure should be printed. E.g. |
max_length |
How many elements should be printed? This is useful in case you try and print an object with 100,000 items in it. |
show_environments |
Should environments be treated like normal lists and recursed into? |
hide_scalar_types |
Should atomic scalars be printed with type and
length like vectors? E.g. |
val_printer |
Function that values get passed to before being drawn to screen. Can be used to color or generally style output. |
class_printer |
Same as |
show_attributes |
Should attributes be printed as a child of the list or avoided? |
remove_newlines |
Should character strings with newlines in them have the newlines removed? Not doing so will mess up the vertical flow of the tree but may be desired for some use-cases if newline structure is important to understanding object state. |
tree_chars |
List of box characters used to construct tree. Needs
elements |
console output of structure
x <- list( list(id = "a", val = 2), list( id = "b", val = 1, children = list( list(id = "b1", val = 2.5), list( id = "b2", val = 8, children = list( list(id = "b21", val = 4) ) ) ) ), list( id = "c", val = 8, children = list( list(id = "c1"), list(id = "c2", val = 1) ) ) ) # Basic usage tree(x) # Even cleaner output can be achieved by not printing indices tree(x, index_unnamed = FALSE) # Limit depth if object is potentially very large tree(x, max_depth = 2) # You can customize how the values and classes are printed if desired tree(x, val_printer = function(x) { paste0("_", x, "_") })
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.