If the data.tree::data.tree package is installed, this function can be used to convert a list of objects, as loaded from extracted YAML fragments, into a data.tree::Node().

build_tree(
  x,
  idName = "id",
  parentIdName = "parentId",
  childrenName = "children",
  autofill = c(label = "id"),
  rankdir = "LR",
  directed = "false",
  silent = TRUE
)

Arguments

x

Either a list of YAML fragments loaded from a file with load_yaml_fragments(), or a list of such lists loaded from all files in a directory with load_yaml_dir().

idName

The name of the field containing each elements' identifier, used to build the data tree when there are references to a parent from a child element.

parentIdName

The name of the field containing references to an element's parent element (i.e. the field containing the identifier of the corresponding parent element).

childrenName

The name of the field containing an element's children, either as a list of elements, or using the 'shorthand' notation, in which case a vector is supplied with the identifiers of the children.

autofill

A named vector where the names represent fields to fill with the values of the fields specified in the vector values. Note that autofill replacements are only applied if the fields to be autofilled (i.e. the names of the vector specified in autofill) do not already have a value.

rankdir

How to plot the plot when it's plotted: the default "LR" plots from left to right. Specify e.g. "TB" to plot from top to bottom.

directed

Whether the edges should have arrows ("forward" or "backward") or not ("false").

silent

Whether to provide (FALSE) or suppress (TRUE) more detailed progress updates.

Value

a data.tree::Node() object.

Examples

loadedYum <- yum::load_yaml_fragments(text=c( "---", "-", " id: firstFragment", "---", "Outside of YAML", "---", "-", " id: secondFragment", " parentId: firstFragment", "---", "Also outside of YAML")); yum::build_tree(loadedYum);
#> levelName #> 1 #> 2 °--firstFragment #> 3 °--secondFragment