Skip to content

Commit

Permalink
adding examples to all exported functions
Browse files Browse the repository at this point in the history
  • Loading branch information
lorenzwalthert committed Dec 5, 2017
1 parent 88c1ca4 commit 7c1a50d
Show file tree
Hide file tree
Showing 9 changed files with 69 additions and 12 deletions.
4 changes: 0 additions & 4 deletions API
Expand Up @@ -12,7 +12,3 @@ style_text(text, ..., style = tidyverse_style, transformers = style(...))
tidyverse_math_token_spacing()
tidyverse_reindention()
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())

## Foreign S3 methods

print.vertical(x, ...)
27 changes: 25 additions & 2 deletions R/style_guides.R
Expand Up @@ -46,6 +46,7 @@ NULL
#' @family style_guides
#' @examples
#' style_text("call( 1)", style = tidyverse_style, scope = "spaces")
#' style_text("call( 1)", transformers = tidyverse_style(strict = TRUE))
#' style_text(c("ab <- 3", "a <-3"), strict = FALSE) # keeps alignment of "<-"
#' style_text(c("ab <- 3", "a <-3"), strict = TRUE) # drops alignment of "<-"
#' @importFrom purrr partial
Expand Down Expand Up @@ -153,8 +154,8 @@ tidyverse_style <- function(scope = "tokens",
#' transformer function corresponds to one styling rule. The output of this
#' function can be used as an argument for \code{style} in top level functions
#' like [style_text()] and friends.
#' @param initialize A function that initializes various variables on each
#' level of nesting.
#' @param initialize The bare name of a function that initializes various
#' variables on each level of nesting.
#' @param line_break A list of transformer functions that manipulate line_break
#' information.
#' @param space A list of transformer functions that manipulate spacing
Expand All @@ -165,6 +166,16 @@ tidyverse_style <- function(scope = "tokens",
#' should be used.
#' @param reindention A list of parameters for regex re-indention, most
#' conveniently constructed using [specify_reindention()].
#' @examples
#' set_line_break_before_curly_opening <- function(pd_flat) {
#' op <- pd_flat$token %in% "'{'"
#' pd_flat$lag_newlines[op] <- 1L
#' pd_flat
#' }
#' set_line_break_before_curly_opening_style <- function() {
#' create_style_guide(line_break = set_line_break_before_curly_opening)
#' }
#' style_text("a <- function(x) { x }", style = set_line_break_before_curly_opening_style)
#' @export
create_style_guide <- function(initialize = initialize_attributes,
line_break = NULL,
Expand Down Expand Up @@ -205,6 +216,10 @@ NULL

#' @describeIn reindention Allows to specify which tokens are reindented and
#' how.
#' @examples
#' style_text("a <- xyz", reindention = specify_reindention(
#' regex_pattern = "xyz", indention = 4, comments_only = FALSE)
#' )
#' @export
specify_reindention <- function(regex_pattern = NULL,
indention = 0,
Expand All @@ -218,6 +233,8 @@ specify_reindention <- function(regex_pattern = NULL,
#' @describeIn reindention Simple forwarder to
#' `specify_reindention` with reindention according to the tidyverse style
#' guide.
#' @examples
#' style_text("a <- xyz", reindention = tidyverse_reindention())
#' @export
tidyverse_reindention <- function() {
specify_reindention(
Expand Down Expand Up @@ -281,6 +298,12 @@ specify_math_token_spacing <-
#' @describeIn math_token_spacing Simple forwarder to
#' `specify_math_token_spacing` with spacing around math tokens according to the
#' tidyverse style guide.
#' @examples
#' style_text(
#' "1+1 -3",
#' math_token_spacing = tidyverse_math_token_spacing(),
#' strict = TRUE
#' )
#' @export
tidyverse_math_token_spacing <- function() {
specify_math_token_spacing(one = c("'+'", "'-'", "'*'", "'/'", "'^'"))
Expand Down
11 changes: 9 additions & 2 deletions R/ui.R
Expand Up @@ -31,9 +31,12 @@ NULL
#' @family stylers
#' @examples
#' \dontrun{
#' # the following is identical but the former is more convenient:
#'
#' style_pkg(style = tidyverse_style, strict = TRUE)
#' style_pkg(transformers = tidyverse_style(strict = TRUE))
#' style_pkg(
#' scope = "line_breaks",
#' math_token_spacing = specify_math_token_spacing(zero = "'+'")
#' )
#' }
#' @export
style_pkg <- function(pkg = ".",
Expand Down Expand Up @@ -112,6 +115,10 @@ style_text <- function(text,
#' @inheritSection transform_files Value
#' @inheritSection style_pkg Warning
#' @family stylers
#' @examples
#' \dontrun{
#' style_dir(file_type = "r")
#' }
#' @export
style_dir <- function(path = ".",
...,
Expand Down
15 changes: 13 additions & 2 deletions man/create_style_guide.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

5 changes: 5 additions & 0 deletions man/math_token_spacing.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 6 additions & 0 deletions man/reindention.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

5 changes: 5 additions & 0 deletions man/style_dir.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

7 changes: 5 additions & 2 deletions man/style_pkg.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions man/tidyverse_style.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit 7c1a50d

Please sign in to comment.