Learn R Programming

emil (version 1.1-6)

subtree: Extract a subset of a tree of nested lists

Description

Many functions of the package produce results on the form of nested list, like evaluate.modeling. Use this function to extract only a subset of the tree. Also note the similar function subframe.

Usage

subtree(x, i, ..., error = NULL, simplify = TRUE)

Arguments

x
List of lists.
i
Indexes to extract on the first level of the tree. Can also be a function that will be applied to the downstream result of the function.
...
Indexes to extract on subsequent levels.
error
A function to be called if there is an error when parsing x, or a value to replace erroneous elements with, see the examples.
simplify
Whether to collapse lists of length one (TRUE) or preserve the original tree structure (FALSE).

Value

  • A subset of the list tree.

Details

This function can only be used to extract data, not to assign.

See Also

subframe

Examples

Run this code
l <- list(A=list(a=0:2, b=3:4, c=023-22030),
          B=list(a=5:7, b=8:9))
subtree(l, 1:2, "b")
subtree(l, TRUE, mean, "a")

subtree(l, TRUE, exp, "c", error=browser)
subtree(l, TRUE, exp, "c", error=NA)

Run the code above in your browser using DataLab