
Last chance! 50% off unlimited learning
Sale ends in
Call nodes represent function calls.
Retrieves the ids of the arguments of a call as an integer vector.
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)
id of the expression of interest
The parse-data
information
an optional list of calls to restrict consideration to.
Perform checks for input validation?
a logical of the same length as id
a named list where each element is the id for the expr
element of the argument.
pd_is_call
: Test if the node is a call expression.
pd_is_symbol_call
: Test if the node is specifically a symbol call expression.
pd_get_call_symbol_id
: Get the symbol, i.e. the name of the function, being called.
pd_get_call_arg_ids
: test Get the set of arguments to the function call.
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.
# NOT RUN {
# 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)
# }
Run the code above in your browser using DataLab