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.8 |
Built: | 2025-02-05 10:57:05 UTC |
Source: | CRAN |
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 - the number of spaces to use for indentation.
line_length - the maximum number of characters in a line.
embracing_op_no_nl - whether to allow a newline after an embracing operator.
allow_nl_after_assignment - whether to allow a newline after an assignment operator.
space_before_complex_rhs_in_formula - whether to add a space before a complex right-hand side in a formula.
strip_suffix_whitespace_in_function_defs - whether to strip suffix whitespace in function definitions.
function_line_breaks - the type of line breaks in function definitions when arguments do not fit. Possible values are: hanging, double, single.
insert_newline_in_quote_call - whether to insert a newline in calls to quote
.
list
with the default configuration
config <- get_default_config() print(config) # Make the indent 4 spaces config$indent <- 4 # Make the maximum line length 80 characters config$line_length <- 80
config <- get_default_config() print(config) # Make the indent 4 spaces config$indent <- 4 # Make the maximum line length 80 characters config$line_length <- 80
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()
.
No return value, called for side effects.
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 <- "function(){}" style_text(code) code <- c("function(){}", "A<-7") style_text(code)
code <- "function(){}" style_text(code) code <- c("function(){}", "A<-7") style_text(code)