find_nodes: Find Nodes in an RStatic Object

Description Usage Arguments Details Value Examples

View source: R/find_nodes.R

Description

This function traverses the given RStatic object and returns a list of indices for all descendants that satisfy the given test function.

Usage

1
2
find_nodes(node, test, ..., recursive = TRUE, initial = list(),
  index = integer(0))

Arguments

node

(ASTNode) The RStatic object to search.

test

(function) The test function, which should accept an rstatic object to check as its first argument and return a scalar logical.

...

Additional arguments to the test function.

recursive

(logical) Search recursively in matching nodes?

initial

(list) Initial list of match indices.

index

(integer) The index of node.

Details

All indices are relative to node, unless index is supplied.

Note that node itself is not tested.

Value

A list of indices for matching nodes.

Examples

1
2
3
4
5
6
7
8
9
ast = quote_ast(
  function(x, y) {
    x = x + y
    function() x
  })

find_nodes(ast, is, "Function")

find_nodes(ast, function(node) is(node, "Symbol") && node$name == "x")

nick-ulle/ast documentation built on July 17, 2018, 4:16 a.m.