Performs various substitutions in the files specified. Carefully examine the results after running this function!

style_file(path, ..., style = tidyverse_style, transformers = style(...))

Arguments

path

A character vector with paths to files to style.

...

Arguments passed on to the style function.

style

A function that creates a style guide to use, by default tidyverse_style() (without the parentheses). Not used further except to construct the argument transformers. See style_guides() for details.

transformers

A set of transformer functions. This argument is most conveniently constructed via the style argument and .... See 'Examples'.

Value

Invisibly returns a data frame that indicates for each file considered for styling whether or not it was actually changed.

Warning

This function overwrites files (if styling results in a change of the code to be formatted). It is strongly suggested to only style files that are under version control or to create a backup copy.

See also

Other stylers: style_dir, style_pkg, style_text, styler_addins

Examples

# the following is identical but the former is more convenient: file <- tempfile("styler", fileext = ".R") enc::write_lines_enc("1++1", file) style_file(file, style = tidyverse_style, strict = TRUE)
#> Styling 1 files: #> styler31e774be145a.R ℹ #> ──────────────────────────────────────── #> Status Count Legend #> ✔ 0 File unchanged. #> ℹ 1 File changed. #> ✖ 0 Styling threw an error. #> ──────────────────────────────────────── #> Please review the changes carefully!
style_file(file, transformers = tidyverse_style(strict = TRUE))
#> Styling 1 files: #> styler31e774be145a.R ✔ #> ──────────────────────────────────────── #> Status Count Legend #> ✔ 1 File unchanged. #> ℹ 0 File changed. #> ✖ 0 Styling threw an error. #> ────────────────────────────────────────
enc::read_lines_enc(file)
#> [1] "1 + +1"
unlink(file)