1010NULL
1111
1212# ' @describeIn pd_is Checks whether `pd` contains an expression wrapped in curly brackets.
13+ # ' @examples
14+ # ' code <- "if (TRUE) { 1 }"
15+ # ' pd <- compute_parse_data_nested(code)
16+ # ' is_curly_expr(pd)
17+ # ' is_curly_expr(pd$child$`17`$child$`14`)
18+ # '
1319# ' @export
1420is_curly_expr <- function (pd ) {
1521 if (is.null(pd )) {
@@ -19,12 +25,24 @@ is_curly_expr <- function(pd) {
1925}
2026
2127# ' @describeIn pd_is Checks whether `pd` contains a `for` loop.
28+ # ' @examples
29+ # ' code <- "for (i in 1:5) print(1:i)"
30+ # ' pd <- compute_parse_data_nested(code)
31+ # ' is_for_expr(pd)
32+ # ' is_for_expr(pd$child$`30`)
33+ # '
2234# ' @export
2335is_for_expr <- function (pd ) {
2436 pd $ token [1L ] == " FOR"
2537}
2638
2739# ' @describeIn pd_is Checks whether `pd` contains is a conditional expression.
40+ # ' @examples
41+ # ' code <- "if (TRUE) x <- 1 else x <- 0"
42+ # ' pd <- compute_parse_data_nested(code)
43+ # ' is_conditional_expr(pd)
44+ # ' is_conditional_expr(pd$child$`24`)
45+ # '
2846# ' @export
2947is_conditional_expr <- function (pd ) {
3048 pd $ token [1L ] == " IF"
@@ -43,6 +61,7 @@ is_while_expr <- function(pd) {
4361# ' pd <- compute_parse_data_nested(code)
4462# ' is_function_call(pd)
4563# ' is_function_call(pd$child$`19`$child$`17`)
64+ # '
4665# ' @export
4766is_function_call <- function (pd ) {
4867 if (is.null(pd )) {
@@ -55,6 +74,12 @@ is_function_call <- function(pd) {
5574}
5675
5776# ' @describeIn pd_is Checks whether `pd` is a function declaration.
77+ # ' @examples
78+ # ' code <- "foo <- function() NULL"
79+ # ' pd <- compute_parse_data_nested(code)
80+ # ' is_function_declaration(pd)
81+ # ' is_function_declaration(pd$child$`12`$child$`11`)
82+ # '
5883# ' @export
5984is_function_declaration <- function (pd ) {
6085 if (is.null(pd )) {
@@ -64,6 +89,11 @@ is_function_declaration <- function(pd) {
6489}
6590
6691# ' @describeIn pd_is Checks for every token whether or not it is a comment.
92+ # ' @examples
93+ # ' code <- "x <- 1 # TODO: check value"
94+ # ' pd <- compute_parse_data_nested(code)
95+ # ' is_comment(pd)
96+ # '
6797# ' @export
6898is_comment <- function (pd ) {
6999 if (is.null(pd )) {
@@ -77,6 +107,13 @@ is_comment <- function(pd) {
77107# ' A tilde is on the top row in the parse table if it is an asymmetric tilde
78108# ' expression (like `~column`), in the second row if it is a symmetric tilde
79109# ' expression (like `a~b`).
110+ # ' @examples
111+ # ' code <- "lm(wt ~ mpg, mtcars)"
112+ # ' pd <- compute_parse_data_nested(code)
113+ # ' is_tilde_expr(pd$child$`20`$child$`10`)
114+ # ' is_symmetric_tilde_expr(pd$child$`20`$child$`10`)
115+ # ' is_asymmetric_tilde_expr(pd$child$`20`$child$`10`)
116+ # '
80117# ' @export
81118is_tilde_expr <- function (pd , tilde_pos = c(1L , 2L )) {
82119 if (is.null(pd ) || nrow(pd ) == 1L ) {
0 commit comments