Description Usage Arguments Details Functions Examples
These function help identify and navigate assignments in parse data.
1 2 3 4 5 | pd_is_assignment(id, pd, .check = TRUE)
pd_get_assign_value_id(id, pd, .check = TRUE)
pd_get_assign_variable_id(id, pd, .check = TRUE)
|
id |
id of the expression of interest |
pd |
The |
.check |
Perform checks for input validation? |
These functions only deal with assignment operators.
Using base::assign()
or base::delayedAssign()
are considered
calls in terms of parse data.
There are five assignment operators grouped into three categories.
Left assignment, the <-
and <<-
,
right assignment, ->
and the rarely used ->>
and the equals assignment =
.
pd_is_assignment
: Check if the node is an assignment expression.
pd_get_assign_value_id
: Get the id for the value portion of an assignment.
pd_get_assign_variable_id
: Get the variable of an assignment.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 | # 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)
# The first should be an assignment
pd_is_assignment(roots[[1]], pd=pd)
# the variable/value of the assignment can be accessed by
variable.id <- pd_get_assign_variable_id(roots[[1]], pd)
value.id <- pd_get_assign_value_id(roots[[1]], pd)
# Note that these function will give the variable/value part
# for both LEFT_ASSIGN and RIGHT_ASSIGN operators, going by order
# of ids, or position in the data may not give the expected results.
|
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.