Skip to content

Commit 4e3ff94

Browse files
Merge pull request #154 from lorenzwalthert/tidyup
Finalize function documentation (#154).
2 parents 5551b43 + 1e825f6 commit 4e3ff94

11 files changed

+89
-64
lines changed

R/nested.R

Lines changed: 1 addition & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -7,23 +7,6 @@
77
#' @return A nested parse table. Apart from the columns provided by
88
#' `utils::getParseData()`, a column "short" with the first five characters of
99
#' "text" is added, the nested subtibbles are in column "child".
10-
#' TODO:
11-
#' - Implement enhance_parse_data_nested()
12-
#' - Walk tree defined by `child`, compute whitespace information
13-
#' - Store indention depth in a separate column, unaffected by
14-
#' inter-token space
15-
#' - Implement compute_parse_data_nested_with_ws() as
16-
#' compute_parse_data_nested() + enhance_parse_data_nested()
17-
#' - Implement serialization of nested parse data
18-
#' - Use compute_parse_data_nested_with_ws() instead of
19-
#' compute_parse_data_flat_enhanced()
20-
#' - Perform all transformations on hierarchical structure
21-
#' - Compute text for a sub-element
22-
#' - Compute indentation
23-
#' - Braces
24-
#' - Function calls
25-
#' - Function definitions
26-
#' - Remove `includeText = TRUE`
2710
compute_parse_data_nested <- function(text) {
2811
parse_data <- tokenize(text) %>%
2912
add_terminal_token_before() %>%
@@ -150,7 +133,7 @@ nest_parse_data <- function(pd_flat) {
150133

151134
#' Combine child and internal child
152135
#'
153-
#' binds two parse tables together and arranges them so that the tokens are in
136+
#' Binds two parse tables together and arranges them so that the tokens are in
154137
#' the correct order.
155138
#' @param child A parse table or `NULL`.
156139
#' @param internal_child A parse table or `NULL`.

R/style_guides.R

Lines changed: 23 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,28 @@
1+
#' Style guides
2+
#'
3+
#' Format code according to a style guide. Style guides are the input to the
4+
#' argument `style` in [style_file()] and friends.
5+
#' The available style guides are:
6+
#' * the tidyverse style guide (see [tidyverse_style()]).
7+
#' @name style_guides
8+
NULL
9+
10+
111
#' The tidyverse style
12+
#'
13+
#' Style code according to the tidyverse style guide.
214
#' @param scope The extent of manipulation. Can range from "none" (least
315
#' invasive) to "token" (most invasive). See 'Details'. This argument is a
416
#' vector of length one.
517
#' @param indent_by How many spaces of indention should be inserted after
618
#' operators such as '('.
719
#' @param strict A logical value indicating whether a set of strict
8-
#' or not so strict transformer functions should be returned.
20+
#' or not so strict transformer functions should be returned. Compare the
21+
#' functions returned with or without `strict = TRUE`. For example,
22+
#' `strict = TRUE` means force *one* space e.g. after "," and *one* line break
23+
#' e.g. after a closing curly brace. `strict = FALSE` means to set spaces and
24+
#' line breaks to one if there is none and leave the code untouched otherwise.
25+
#' See 'Examples'.
926
#' @param start_comments_with_one_space Whether or not comments should start
1027
#' with only one space (see [start_comments_with_space()]).
1128
#' @details The following options for `scope` are available.
@@ -22,6 +39,11 @@
2239
#' As it becomes clear from this description, more invasive operations can only
2340
#' be performed if all less invasive operations are performed too.
2441
#' @family obtain transformers
42+
#' @family style_guides
43+
#' @examples
44+
#' style_text("call( 1)", style = tidyverse_style, scope = "spaces")
45+
#' style_text(c("ab <- 3", "a <-3"), strict = FALSE) # keeps alignment of "<-"
46+
#' style_text(c("ab <- 3", "a <-3"), strict = TRUE) # drops alignment of "<-"
2547
#' @importFrom purrr partial
2648
#' @export
2749
tidyverse_style <- function(scope = "tokens",

R/ws.R

Lines changed: 13 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -12,10 +12,15 @@ NULL
1212
#'
1313
#' @param pkg Path to a (subdirectory of an) R package.
1414
#' @param ... Passed on to the `style` function.
15-
#' @param style A function that creates a style guide to use, by default
16-
#' [tidyverse_style()] (without the parentheses). Will not be used further
17-
#' except to construct the argument `transformers`.
15+
#' @param style The unquoted name of a style guide to use. Will not be used
16+
#' further except to construct the argument `transformers`. See
17+
#' [style_guides()] for details.
1818
#' @param transformers A set of transformer functions.
19+
#' @family stylers
20+
#' @examples
21+
#' \dontrun{
22+
#' style_pkg()
23+
#' }
1924
#' @export
2025
#' @family stylers
2126
style_pkg <- function(pkg = ".",
@@ -45,10 +50,14 @@ prettify_local <- function(transformers) {
4550

4651
#' Style a string
4752
#'
48-
#' Styles a character vector
53+
#' Styles a character vector. Each element of the character vector corresponds
54+
#' to one line of code.
4955
#' @param text A character vector with text to style.
5056
#' @inheritParams style_pkg
5157
#' @family stylers
58+
#' @examples
59+
#' style_text("call( 1)")
60+
#' style_text("1 + 1", strict = FALSE)
5261
#' @export
5362
style_text <- function(text,
5463
...,

man/combine_children.Rd

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

man/compute_parse_data_nested.Rd

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

man/style_dir.Rd

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

man/style_file.Rd

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

man/style_guides.Rd

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

man/style_pkg.Rd

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

man/style_text.Rd

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

man/tidyverse_style.Rd

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

0 commit comments

Comments
 (0)