root: Root IDs

Description Usage Arguments Details Functions See Also Examples

Description

Root IDs constitute the id of a stand alone expression. That is one that is not contained inside of another call or expression. The one exception to this is code blocks denoted by curly braces that are not themselves part of another call or expression; these we call code groups. In definition, A root node is defined to be a node that either has no parent or whose parent is a grouping node.

Usage

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
pd_is_root(id, pd, ignore.groups = TRUE, .check = TRUE)

pd_all_root_ids(pd, include.groups = TRUE)

ascend_to_root(
  id = pd$id,
  pd = get("pd", parent.frame()),
  ignore.groups = TRUE,
  .check = TRUE
)

Arguments

id

id of the expression of interest

pd

The parse-data information

ignore.groups

Should groupings be ignored?

.check

Perform checks for input validation?

include.groups

Include groups as root nodes (T) or descend into groups for roots?

Details

If ignore.groups=TRUE then groupings are ignored and root nodes within the group are interpreted as roots, otherwise nodes within a group are not interpreted as root. Groupings are always interpreted as root if the parent is 0 or if the parent is a group and also a root.

Functions

See Also

see pd_is_grouping for details on what a grouping is.

Examples

1
2
3
4
5
6
7
8
# load example file and get_parse data
ex.file <- system.file("examples", "example.R", package="parsetools")
exprs <- parse(ex.file, keep.source = TRUE)
pd <- get_parse_data(exprs)

# There are 3 expressions so there should be three roots.
sum(pd_is_root(pd$id, pd))
roots <- pd_all_root_ids(pd)

RDocTaskForce/parsetools documentation built on April 10, 2020, 11:58 p.m.