calls: Call nodes

Description Usage Arguments Details Value Functions Examples

Description

Call nodes represent function calls.

Retrieves the ids of the arguments of a call as an integer vector.

Usage

1
2
3
4
5
6
7
pd_is_call(id, pd, calls = NULL, .check = TRUE)

pd_is_symbol_call(id, pd, .check = TRUE)

pd_get_call_symbol_id(id, pd, .check = TRUE)

pd_get_call_arg_ids(id, pd, .check = TRUE)

Arguments

id

id of the expression of interest

pd

The parse-data information

calls

an optional list of calls to restrict consideration to.

.check

Perform checks for input validation?

Details

The traditional call of function_name(arguments) is a symbol call as function_name is the symbol directly referencing the function to call. Other calls may exists such as function_array[[1]]() which first indexes the function_array then calls the returned function. This qualifies as a call expression but not a symbol call expression. We are often only concerned with symbol calls and not the anonymous version.

Value

a logical of the same length as id

a named list where each element is the id for the expr element of the argument.

Functions

Examples

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
# 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)

# which root is a call?
pd_is_call(roots, pd)
id <- roots[pd_is_call(roots, pd)]
# not all calls are symbole calls.
pd_is_symbol_call(id, pd)
# what is the symbol being called?
pd_text(pd_get_call_symbol_id(id, pd), pd)
# what are the arguments to the call
args <- pd_get_call_arg_ids(id, pd)
pd_token(pd_get_firstborn(args, pd), pd)
pd_text(pd_get_firstborn(args, pd), pd)

parsetools documentation built on April 14, 2020, 5:32 p.m.