diff --git a/R/detect-alignment-utils.R b/R/detect-alignment-utils.R index 9be7d0871..ce2596e6a 100644 --- a/R/detect-alignment-utils.R +++ b/R/detect-alignment-utils.R @@ -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) { diff --git a/R/rules-line-breaks.R b/R/rules-line-breaks.R index 7bcebbe96..e4e208295 100644 --- a/R/rules-line-breaks.R +++ b/R/rules-line-breaks.R @@ -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")) diff --git a/R/ui-styling.R b/R/ui-styling.R index 2b3c6dd82..734fce38f 100644 --- a/R/ui-styling.R +++ b/R/ui-styling.R @@ -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 = ".", ..., @@ -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 = ".", ..., diff --git a/man/alignment_drop_last_expr.Rd b/man/alignment_drop_last_expr.Rd index dc86683c1..f67092d76 100644 --- a/man/alignment_drop_last_expr.Rd +++ b/man/alignment_drop_last_expr.Rd @@ -12,16 +12,16 @@ 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, - ) +\dontshow{if (FALSE) (if (getRversion() >= "3.4") withAutoprint else force)(\{ # examplesIf} +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 } +\dontshow{\}) # examplesIf} } \keyword{internal} diff --git a/man/set_line_break_before_curly_opening.Rd b/man/set_line_break_before_curly_opening.Rd index b5ac5c4b4..c590b58fc 100644 --- a/man/set_line_break_before_curly_opening.Rd +++ b/man/set_line_break_before_curly_opening.Rd @@ -19,48 +19,48 @@ line trigger. } } \examples{ -if (FALSE) { - tryCatch( - { - f(8) - }, - error = function(e) NULL - ) - # last-argument case - testthat("braces braces are cool", { +\dontshow{if (FALSE) (if (getRversion() >= "3.4") withAutoprint else force)(\{ # examplesIf} +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") + } +\dontshow{\}) # examplesIf} } \keyword{internal} diff --git a/man/style_dir.Rd b/man/style_dir.Rd index 5ad03618f..446172e68 100644 --- a/man/style_dir.Rd +++ b/man/style_dir.Rd @@ -111,15 +111,15 @@ See section 'Warning' for a good strategy to apply styling safely. } \examples{ -if (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)) -} +\dontshow{if (FALSE) (if (getRversion() >= "3.4") withAutoprint else force)(\{ # examplesIf} +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)) +\dontshow{\}) # examplesIf} } \seealso{ Other stylers: diff --git a/man/style_pkg.Rd b/man/style_pkg.Rd index 31d169b61..d398bb0d6 100644 --- a/man/style_pkg.Rd +++ b/man/style_pkg.Rd @@ -108,22 +108,22 @@ styling whether or not it was actually changed (or would be changed when } \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)) - - # 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") -} +\dontshow{if (FALSE) (if (getRversion() >= "3.4") withAutoprint else force)(\{ # examplesIf} +# 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 = "'+'") +) + +# don't write back and fail if input is not already styled +style_pkg("/path/to/pkg/", dry = "fail") +\dontshow{\}) # examplesIf} } \seealso{ Other stylers: