tree_json: Generate a nested list representing a tree structure

Description Usage Arguments Value Examples

View source: R/prep_data.R

Description

This representation is easily converted to the json required by d3 by using toJSON in the jsonlite package.

Usage

1
tree_json(el, cur_node)

Arguments

el

[data.frame] A data.frame with names "parent" and "child", giving the edgelist for the tree structure to generate. Columns called "length" or "depth" will also be accepted and stored in the resulting list.

cur_node

The name of the root node in the edgelist, from which to start the recursive descent.

Value

[list] A nested list whose structure reflects the edgelist in el. At each level, "name" is a character string specifying the name of the root in the subtree and children is a list with the same structure as the overall tree. If "length" or "depth" are provided in "el", this information is stored along with "name".

Examples

1
2
3
4
5
6
el <- data.frame(
  parent = c("1", "1", "2", "2", "3", "3"),
  child = c("2", "3", "4", "5", "6", "7"),
  stringsAsFactors = FALSE
)
tree_json(el, "1")

krisrs1128/treelapse documentation built on Jan. 3, 2020, 6:29 p.m.