This is a helper function to create a style guide, which is technically speaking a named list of groups of transformer functions where each transformer function corresponds to one styling rule. The output of this function can be used as an argument for style in top level functions like style_text() and friends.

create_style_guide(
  initialize = default_style_guide_attributes,
  line_break = NULL,
  space = NULL,
  token = NULL,
  indention = NULL,
  use_raw_indention = FALSE,
  reindention = tidyverse_reindention(),
  style_guide_name = NULL,
  style_guide_version = NULL
)

Arguments

initialize

The bare name of a function that initializes various variables on each level of nesting.

line_break

A list of transformer functions that manipulate line_break information.

space

A list of transformer functions that manipulate spacing information.

token

A list of transformer functions that manipulate token text.

indention

A list of transformer functions that manipulate indention.

use_raw_indention

Boolean indicating whether or not the raw indention should be used.

reindention

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

style_guide_name

The name of the style guide. Used as a meta attribute inside the created style guide, for example for caching. By convention, this is the style guide qualified by the package namespace plus the location of the style guide, separated by @. For example, "styler::tidyverse_style@https://github.com/r-lib".

style_guide_version

The version of the style guide. Used as a meta attribute inside the created style guide, for example for caching. This should correspond to the version of the R package that exports the style guide.

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 = tibble::lst(set_line_break_before_curly_opening) ) } style_text( "a <- function(x) { x }", style = set_line_break_before_curly_opening_style )
#> Warning: Style guides without a name and a version field are depreciated and won't be supported in styler >= 1.4. #> If you are a user: Open an issue on https://github.com/r-lib/styler and provide a reproducible example of this error. #> If you are a developer: When you create a style guide with `styler::create_style_guide()`, the argument `style_guide_name` and `style_guide_version` should be non-NULL. See help("create_style_guide") for how to set them.
#> a <- function(x) #> { x }