| Title: | Style Your Code Fast |
|---|---|
| Description: | Provides a set of functions that allow users for styling their R code according to the 'tidyverse' style guide. The package uses a native Rust implementation to ensure the highest performance. Learn more about 'tergo' at <https://rtergo.pagacz.io>. |
| Authors: | Konrad Pagacz [aut, cre], Maciej Nasinski [ctb], The authors of the dependency Rust crates [ctb] (see inst/AUTHORS file for details) |
| Maintainer: | Konrad Pagacz <[email protected]> |
| License: | MIT + file LICENSE |
| Version: | 0.1.10.9000 |
| Built: | 2026-05-25 08:10:52 UTC |
| Source: | https://github.com/kpagacz/tergo |
This configuration is used by the styling functions if no value is provided for the configuration keys. It can also serve as the base for you custom configuration.
get_default_config()get_default_config()
The configuration values:
indent (integer) - the number of spaces to use for indentation. E.g. 2L, 4L.
line_length (integer) - the maximum number of characters in a line. E.g. 80L, 120L.
embracing_op_no_nl (logical) - whether to allow a newline after an embracing operator. E.g.
TRUE, FALSE.
allow_nl_after_assignment (logical) - whether to allow a newline after an assignment operator.
E.g. TRUE, FALSE.
space_before_complex_rhs_in_formula (logical) - whether to add a space before a complex
right-hand side in a formula. E.g. TRUE, FALSE.
strip_suffix_whitespace_in_function_defs (logical) - whether to strip suffix
whitespace in function definitions. E.g. TRUE, FALSE.
function_line_breaks (character) - the type of line breaks in function definitions when arguments do not
fit. Possible values are: "hanging", "double", "single".
insert_newline_in_quote_call (logical) - whether to insert a newline in calls to quote.
E.g. TRUE, FALSE.
list with the default configuration
config <- get_default_config() print(config) # Make the indent 4 spaces config$indent <- 4L # Make the maximum line length 80 characters config$line_length <- 80L # Make the function line breaks double config$function_line_breaks <- "double"config <- get_default_config() print(config) # Make the indent 4 spaces config$indent <- 4L # Make the maximum line length 80 characters config$line_length <- 80L # Make the function line breaks double config$function_line_breaks <- "double"
Style a package
style(config_file = "tergo.toml", configuration = list(), ...)style(config_file = "tergo.toml", configuration = list(), ...)
config_file |
( |
configuration |
( |
... |
additional parameters to |
Configuration is read from a file named tergo.toml in the root of the
package. The precedence of the configuration is (from the highest to lowest):
The configuration passed to the function.
The configuration file.
To see possible configuration options, see get_default_config().
No return value, called for side effects.
style() style(config_file = "tergo.toml", configuration = list())style() style(config_file = "tergo.toml", configuration = list())
Style a file
style_file(file, configuration = list())style_file(file, configuration = list())
file |
( |
configuration |
( |
To see possible configuration options, see get_default_config().
(logical) whether the file was formatted successfully
or skipped. TRUE - formatted successfully, FALSE - skipped.
tmp <- tempfile() file_conn <- file(tmp) writeLines(c("function(){}", "A<-7"), file_conn) close(file_conn) style_file(file = tmp, configuration = list()) unlink(tmp)tmp <- tempfile() file_conn <- file(tmp) writeLines(c("function(){}", "A<-7"), file_conn) close(file_conn) style_file(file = tmp, configuration = list()) unlink(tmp)
Style a package
style_pkg( path = ".", config_file = "tergo.toml", configuration = list(), force = FALSE, extensions = c(".R", ".r"), verbose = interactive() )style_pkg( path = ".", config_file = "tergo.toml", configuration = list(), force = FALSE, extensions = c(".R", ".r"), verbose = interactive() )
path |
( |
config_file |
( |
configuration |
( |
force |
( |
extensions |
( |
verbose |
( |
Configuration is read from a file named tergo.toml in the root of the
package. The precedence of the configuration is (from the highest to lowest):
The configuration passed to the function.
The configuration file.
To see possible configuration options, see get_default_config().
No return values, called for side effects.
style_pkg() style_pkg(path = "./tergo", config_file = "custom_tergo.toml", verbose = TRUE)style_pkg() style_pkg(path = "./tergo", config_file = "custom_tergo.toml", verbose = TRUE)
Style text
style_text(text, configuration = list())style_text(text, configuration = list())
text |
( |
configuration |
( |
This function is vectorized.
To see possible configuration options, see get_default_config().
(character) The text formatted as R code.
code <- "a+b" styled <- style_text(code) code <- c("a+b", "A<-7") styled <- style_text(code)code <- "a+b" styled <- style_text(code) code <- c("a+b", "A<-7") styled <- style_text(code)