tidyverse_style {styler}R Documentation

The tidyverse style

Description

Style code according to the tidyverse style guide.

Usage

tidyverse_style(
  scope = "tokens",
  strict = TRUE,
  indent_by = 2L,
  start_comments_with_one_space = FALSE,
  reindention = tidyverse_reindention(),
  math_token_spacing = tidyverse_math_token_spacing()
)

Arguments

scope

The extent of manipulation. Can range from "none" (least invasive) to "tokens" (most invasive). See 'Details'. This argument is a string or a vector of class AsIs.

strict

A logical value indicating whether a set of strict or not so strict transformer functions should be returned. Compare the functions returned with or without strict = TRUE. For example, strict = TRUE means force one space e.g. after "," and one line break e.g. after a closing curly brace. strict = FALSE means to set spaces and line breaks to one if there is none and leave the code untouched otherwise. See 'Examples'.

indent_by

How many spaces of indention should be inserted after operators such as '('.

start_comments_with_one_space

Whether or not comments should start with only one space (see start_comments_with_space()).

reindention

A list of parameters for regex re-indention, most conveniently constructed using specify_reindention().

math_token_spacing

A list of parameters that define spacing around math token, conveniently constructed using specify_math_token_spacing().

Details

The following levels for scope are available:

scope can be specified in two ways:

See 'Examples' for details.

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 "<-"

# styling line breaks only without spaces
style_text(c("ab <- 3", "a =3"), strict = TRUE, scope = I(c("line_breaks", "tokens")))

[Package styler version 1.10.3 Index]