Description Usage Arguments Details Value Functions Examples
These function navigate logic statements.
Returns the id of the predicate of the if statement, i.e. the conditional statement.
Returns the id of the body of the branch executed if the predicate evaluates to true.
Gets the id of the alternate branch, i.e. the else branch.
1 2 3 4 5 6 7 | pd_is_if(id, pd, .check = TRUE)
pd_get_if_predicate_id(id, pd, .check = TRUE)
pd_get_if_branch_id(id, pd, .check = TRUE)
pd_get_if_alternate_id(id, pd, .check = TRUE)
|
id |
id of the expression of interest |
pd |
The |
.check |
Perform checks for input validation? |
If statements have the form of the following.
1 | if (predicate) branch else alternate
|
The predicate
refers to the logical test being performed.
The branch
is the statement or block that is executed if predicate
evaluates true.
The alternate
is the statement of block that is executed if predicate
returns false.
an id integer.
an id integer.
pd_is_if
: Is node an if expression.
pd_get_if_predicate_id
: Get the predicate node.
pd_get_if_branch_id
: Get the branch
statement or block node.
pd_get_if_alternate_id
: Get the alternate
statement or block node.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 | # 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)
# Find the if statement
is.if <- pd_is_if(pd$id, pd=pd)
sum(is.if)
if.id <- pd$id[is.if]
# The predicate
pd_reconstitute(pd_get_if_predicate_id(if.id, pd), pd)
# The branch for if predicate evaluates TRUE
pd_reconstitute(pd_get_if_branch_id(if.id, pd), pd)
# The alternate for if predicate evaluates FALSE
pd_reconstitute(pd_get_if_alternate_id(if.id, pd), pd)
|
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.