Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 8 additions & 10 deletions R/detect-alignment-utils.R
Original file line number Diff line number Diff line change
Expand Up @@ -46,17 +46,15 @@ alignment_drop_comments <- function(pd_by_line) {
#' an if, while or for statement or a function call. We don't call about that
#' part, in fact it's important to remove it for alignment. See 'Examples'.
#'
#' @examples
#' if (FALSE) {
#' call(
#' x = 12,
#' y = 3,
#' )
#' @examplesIf FALSE
#' call(
#' x = 12,
#' y = 3,
#' )
#'
#' function(a = 33,
#' qq = 4) {
#' # we don't care about this part for alignment detection
#' }
#' function(a = 33,
#' qq = 4) {
#' # we don't care about this part for alignment detection
#' }
#' @keywords internal
alignment_drop_last_expr <- function(pds_by_line) {
Expand Down
72 changes: 35 additions & 37 deletions R/rules-line-breaks.R
Original file line number Diff line number Diff line change
Expand Up @@ -9,50 +9,48 @@
#' * Extension: Also, expressions following on braced expressions also cause a
#' line trigger.
#' @keywords internal
#' @examples
#' if (FALSE) {
#' tryCatch(
#' {
#' f(8)
#' },
#' error = function(e) NULL
#' )
#' # last-argument case
#' testthat("braces braces are cool", {
#' @examplesIf FALSE
#' tryCatch(
#' {
#' f(8)
#' },
#' error = function(e) NULL
#' )
#' # last-argument case
#' testthat("braces braces are cool", {
#' code(to = execute)
#' })
#' call2(
#' x = 2, {
#' code(to = execute)
#' })
#' call2(
#' x = 2, {
#' code(to = execute)
#' },
#' c = {
#' # this is the named case
#' g(x = 7)
#' }
#' )
#' tryGugus(
#' {
#' g5(k = na)
#' },
#' a + b # line break also here because
#' # preceded by brace expression
#' )
#' },
#' c = {
#' # this is the named case
#' g(x = 7)
#' }
#' )
#' tryGugus(
#' {
#' g5(k = na)
#' },
#' a + b # line break also here because
#' # preceded by brace expression
#' )
#'
#' # brace expressions go on new line if part of a pipe, in function call...
#' c(
#' data %>%
#' filter(bar) %>%
#' {
#' cor(.$col1, .$col2, use = "complete.obs")
#' }
#' )
#' # ... or outside
#' # brace expressions go on new line if part of a pipe, in function call...
#' c(
#' data %>%
#' filter(bar) %>%
#' {
#' cor(.$col1, .$col2, use = "complete.obs")
#' }
#' }
#' )
#' # ... or outside
#' data %>%
#' filter(bar) %>%
#' {
#' cor(.$col1, .$col2, use = "complete.obs")
#' }
set_line_break_before_curly_opening <- function(pd) {
line_break_to_set_idx <- which(
(pd$token_after == "'{'") & !(pd$token %in% c("COMMENT", "EQ_FORMALS"))
Expand Down
44 changes: 20 additions & 24 deletions R/ui-styling.R
Original file line number Diff line number Diff line change
Expand Up @@ -48,23 +48,21 @@
#' See section 'Warning' for a good strategy to apply styling safely.
#' @inheritSection transform_files Value
#' @family stylers
#' @examples
#' if (FALSE) {
#' # the following is identical (because of ... and defaults)
#' # but the first is most convenient:
#' style_pkg(strict = TRUE)
#' style_pkg(style = tidyverse_style, strict = TRUE)
#' style_pkg(transformers = tidyverse_style(strict = TRUE))
#' @examplesIf FALSE
#' # the following is identical (because of ... and defaults)
#' # but the first is most convenient:
#' style_pkg(strict = TRUE)
#' style_pkg(style = tidyverse_style, strict = TRUE)
#' style_pkg(transformers = tidyverse_style(strict = TRUE))
#'
#' # more options from `tidyverse_style()`
#' style_pkg(
#' scope = "line_breaks",
#' math_token_spacing = specify_math_token_spacing(zero = "'+'")
#' )
#' # more options from `tidyverse_style()`
#' style_pkg(
#' scope = "line_breaks",
#' math_token_spacing = specify_math_token_spacing(zero = "'+'")
#' )
#'
#' # don't write back and fail if input is not already styled
#' style_pkg("/path/to/pkg/", dry = "fail")
#' }
#' # don't write back and fail if input is not already styled
#' style_pkg("/path/to/pkg/", dry = "fail")
#' @export
style_pkg <- function(pkg = ".",
...,
Expand Down Expand Up @@ -235,16 +233,14 @@ style_text <- function(text,
#' @inheritSection style_pkg Warning
#' @inheritSection style_pkg Round trip validation
#' @family stylers
#' @examples
#' if (FALSE) {
#' style_dir("path/to/dir", filetype = c("rmd", ".R"))
#' @examplesIf FALSE
#' style_dir("path/to/dir", filetype = c("rmd", ".R"))
#'
#' # the following is identical (because of ... and defaults)
#' # but the first is most convenient:
#' style_dir(strict = TRUE)
#' style_dir(style = tidyverse_style, strict = TRUE)
#' style_dir(transformers = tidyverse_style(strict = TRUE))
#' }
#' # the following is identical (because of ... and defaults)
#' # but the first is most convenient:
#' style_dir(strict = TRUE)
#' style_dir(style = tidyverse_style, strict = TRUE)
#' style_dir(transformers = tidyverse_style(strict = TRUE))
#' @export
style_dir <- function(path = ".",
...,
Expand Down
18 changes: 9 additions & 9 deletions man/alignment_drop_last_expr.Rd

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

72 changes: 36 additions & 36 deletions man/set_line_break_before_curly_opening.Rd

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

18 changes: 9 additions & 9 deletions man/style_dir.Rd

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

32 changes: 16 additions & 16 deletions man/style_pkg.Rd

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