Learn R Programming

data.tree (version 0.2.0-3)

as.Node.list: Convert a nested list structure to a data.tree structure

Description

Convert a nested list structure to a data.tree structure

Usage

# S3 method for list
as.Node(x, mode = c("simple", "explicit"), nameName = "name",
  childrenName = "children", nodeName = NULL, ...)

FromListExplicit(explicitList, nameName = "name", childrenName = "children", nodeName = NULL)

FromListSimple(simpleList, nameName = "name", nodeName = NULL)

Arguments

x

The list to be converted.

mode

How the list is structured. "simple" (the default) will interpret any list to be a child. "explicit" assumes that children are in a nested list called childrenName

nameName

The name of the element in the list that should be used as the name, can be NULL if the children lists are named

childrenName

The name of the element that contains the child list (applies to mode 'explicit' only).

nodeName

The name x will get (only applies if no nameName is available, this is useful for some conversions where th name is not given explicitly)

...

Any other argument to be passed to generic sub implementations

explicitList

A list in which children are in a separate nested list called childrenName.

simpleList

A list in which children are stored as nested list alongside other fields. Any list is interpreted as a child Node

See Also

Other as.Node: FromDataFrameNetwork, FromDataFrameTable, as.Node.data.frame; as.Node.dendrogram; as.Node.phylo; as.Node

Examples

Run this code
# NOT RUN {
kingJosephs <- list(name = "Joseph I",
                    spouse = "Mary",
                    born = "1818-02-23",
                    died = "1839-08-29",
                    children = list(
                                    list(name = "Joseph II",
                                         spouse = "Kathryn",
                                         born = "1839-03-28",
                                         died = "1865-12-19"),
                                    list(name = "Helen",
                                         born = "1840-17-08",
                                         died = "1845-01-01")
                                    )
                   )
FromListExplicit(kingJosephs)

kingJosephs <- list(head = "Joseph I",
                    spouse = "Mary",
                    born = "1818-02-23",
                    died = "1839-08-29",
                    list(head = "Joseph II",
                         spouse = "Kathryn",
                         born = "1839-03-28",
                         died = "1865-12-19"),
                    list(head = "Helen",
                         born = "1840-17-08",
                         died = "1845-01-01")
                   )
FromListSimple(kingJosephs, nameName = "head")

kingJosephs <- list(spouse = "Mary",
                    born = "1818-02-23",
                    died = "1839-08-29",
                    `Joseph II` = list(spouse = "Kathryn",
                                       born = "1839-03-28",
                                       died = "1865-12-19"),
                    Helen = list(born = "1840-17-08",
                                 died = "1845-01-01")

                   )
FromListSimple(kingJosephs, nodeName = "Joseph I")
# }

Run the code above in your browser using DataLab