| format_r | R Documentation |
Uses the {styler} and {box.linters} packages to automatically format R sources. As with
styler, carefully examine the results after running this function.
format_r(paths, exclude_files = NULL, ...)
paths |
Character vector of files and directories to format. |
exclude_files |
Character vector with regular expressions of files that should be excluded from styling. |
... |
Optional arguments to pass to |
The code is formatted according to the styler::tidyverse_style guide with one adjustment:
spacing around math operators is not modified to avoid conflicts with box::use() statements.
If available, box::use() calls are reformatted by styling functions provided by
{box.linters}. These include:
Separating box::use() calls for packages and local modules
Alphabetically sorting packages, modules, and functions.
Adding trailing commas
box.linters::style_* functions require the treesitter and treesitter.r packages. These, in
turn, require R >= 4.3.0. format_r() will continue to operate without these but will not
perform box::use() call styling.
For more information on box::use() call styling please refer to the {box.linters} styling
functions
documentation.
None. This function is called for side effects.
if (interactive()) {
# Format a single file.
format_r("app/main.R")
# Format all files in a directory.
format_r("app/view")
}
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.