Skip to content

Commit 5bfd6db

Browse files
Add examples for remaining new exports
1 parent fce1680 commit 5bfd6db

File tree

6 files changed

+90
-4
lines changed

6 files changed

+90
-4
lines changed

R/expr-is.R

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,12 @@
1010
NULL
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
1420
is_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
2335
is_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
2947
is_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
4766
is_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
5984
is_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
6898
is_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
81118
is_tilde_expr <- function(pd, tilde_pos = c(1L, 2L)) {
82119
if (is.null(pd) || nrow(pd) == 1L) {

R/style-guides.R

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -477,8 +477,10 @@ tidyverse_reindention <- function() {
477477
#' @param scope A character vector of length one or a vector of class `AsIs`.
478478
#' @param name The name of the character vector to be displayed if the
479479
#' construction of the factor fails.
480-
#' @keywords internal
481480
#' @importFrom rlang abort
481+
#' @examples
482+
#' scope_normalize(I("tokens"))
483+
#' scope_normalize(I(c("indention", "tokens")))
482484
#' @family third-party style guide helpers
483485
#' @export
484486
scope_normalize <- function(scope, name = substitute(scope)) {

R/utils-navigate-nest.R

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,13 @@
22
#' @param pd A parse table.
33
#' @param pos The position of the token to start the search from.
44
#' @importFrom rlang seq2
5-
#' @keywords internal
5+
#' @examples
6+
#' code <- "a <- # hi \n x %>% b()"
7+
#' writeLines(code)
8+
#' pd <- compute_parse_data_nested(code)
9+
#' child <- pd$child[[1]]
10+
#' previous_non_comment(child, 4L)
11+
#' next_non_comment(child, 2L)
612
#' @family third-party style guide helpers
713
#' @export
814
next_non_comment <- function(pd, pos) {

man/next_non_comment.Rd

Lines changed: 8 additions & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

man/pd_is.Rd

Lines changed: 31 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

man/scope_normalize.Rd

Lines changed: 4 additions & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)