Skip to content

Commit 7c1a50d

Browse files
adding examples to all exported functions
1 parent 88c1ca4 commit 7c1a50d

9 files changed

+69
-12
lines changed

API

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,3 @@ style_text(text, ..., style = tidyverse_style, transformers = style(...))
1212
tidyverse_math_token_spacing()
1313
tidyverse_reindention()
1414
tidyverse_style(scope = "tokens", strict = TRUE, indent_by = 2, start_comments_with_one_space = FALSE, reindention = tidyverse_reindention(), math_token_spacing = tidyverse_math_token_spacing())
15-
16-
## Foreign S3 methods
17-
18-
print.vertical(x, ...)

R/style_guides.R

Lines changed: 25 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,7 @@ NULL
4646
#' @family style_guides
4747
#' @examples
4848
#' style_text("call( 1)", style = tidyverse_style, scope = "spaces")
49+
#' style_text("call( 1)", transformers = tidyverse_style(strict = TRUE))
4950
#' style_text(c("ab <- 3", "a <-3"), strict = FALSE) # keeps alignment of "<-"
5051
#' style_text(c("ab <- 3", "a <-3"), strict = TRUE) # drops alignment of "<-"
5152
#' @importFrom purrr partial
@@ -153,8 +154,8 @@ tidyverse_style <- function(scope = "tokens",
153154
#' transformer function corresponds to one styling rule. The output of this
154155
#' function can be used as an argument for \code{style} in top level functions
155156
#' like [style_text()] and friends.
156-
#' @param initialize A function that initializes various variables on each
157-
#' level of nesting.
157+
#' @param initialize The bare name of a function that initializes various
158+
#' variables on each level of nesting.
158159
#' @param line_break A list of transformer functions that manipulate line_break
159160
#' information.
160161
#' @param space A list of transformer functions that manipulate spacing
@@ -165,6 +166,16 @@ tidyverse_style <- function(scope = "tokens",
165166
#' should be used.
166167
#' @param reindention A list of parameters for regex re-indention, most
167168
#' conveniently constructed using [specify_reindention()].
169+
#' @examples
170+
#' set_line_break_before_curly_opening <- function(pd_flat) {
171+
#' op <- pd_flat$token %in% "'{'"
172+
#' pd_flat$lag_newlines[op] <- 1L
173+
#' pd_flat
174+
#' }
175+
#' set_line_break_before_curly_opening_style <- function() {
176+
#' create_style_guide(line_break = set_line_break_before_curly_opening)
177+
#' }
178+
#' style_text("a <- function(x) { x }", style = set_line_break_before_curly_opening_style)
168179
#' @export
169180
create_style_guide <- function(initialize = initialize_attributes,
170181
line_break = NULL,
@@ -205,6 +216,10 @@ NULL
205216

206217
#' @describeIn reindention Allows to specify which tokens are reindented and
207218
#' how.
219+
#' @examples
220+
#' style_text("a <- xyz", reindention = specify_reindention(
221+
#' regex_pattern = "xyz", indention = 4, comments_only = FALSE)
222+
#' )
208223
#' @export
209224
specify_reindention <- function(regex_pattern = NULL,
210225
indention = 0,
@@ -218,6 +233,8 @@ specify_reindention <- function(regex_pattern = NULL,
218233
#' @describeIn reindention Simple forwarder to
219234
#' `specify_reindention` with reindention according to the tidyverse style
220235
#' guide.
236+
#' @examples
237+
#' style_text("a <- xyz", reindention = tidyverse_reindention())
221238
#' @export
222239
tidyverse_reindention <- function() {
223240
specify_reindention(
@@ -281,6 +298,12 @@ specify_math_token_spacing <-
281298
#' @describeIn math_token_spacing Simple forwarder to
282299
#' `specify_math_token_spacing` with spacing around math tokens according to the
283300
#' tidyverse style guide.
301+
#' @examples
302+
#' style_text(
303+
#' "1+1 -3",
304+
#' math_token_spacing = tidyverse_math_token_spacing(),
305+
#' strict = TRUE
306+
#' )
284307
#' @export
285308
tidyverse_math_token_spacing <- function() {
286309
specify_math_token_spacing(one = c("'+'", "'-'", "'*'", "'/'", "'^'"))

R/ui.R

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -31,9 +31,12 @@ NULL
3131
#' @family stylers
3232
#' @examples
3333
#' \dontrun{
34-
#' # the following is identical but the former is more convenient:
34+
#'
3535
#' style_pkg(style = tidyverse_style, strict = TRUE)
36-
#' style_pkg(transformers = tidyverse_style(strict = TRUE))
36+
#' style_pkg(
37+
#' scope = "line_breaks",
38+
#' math_token_spacing = specify_math_token_spacing(zero = "'+'")
39+
#' )
3740
#' }
3841
#' @export
3942
style_pkg <- function(pkg = ".",
@@ -112,6 +115,10 @@ style_text <- function(text,
112115
#' @inheritSection transform_files Value
113116
#' @inheritSection style_pkg Warning
114117
#' @family stylers
118+
#' @examples
119+
#' \dontrun{
120+
#' style_dir(file_type = "r")
121+
#' }
115122
#' @export
116123
style_dir <- function(path = ".",
117124
...,

man/create_style_guide.Rd

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

man/math_token_spacing.Rd

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

man/reindention.Rd

Lines changed: 6 additions & 0 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: 5 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: 5 additions & 2 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: 1 addition & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)