Title: | Style Your Code Fast |
Version: | 0.1.9 |
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. |
License: | MIT + file LICENSE |
Encoding: | UTF-8 |
RoxygenNote: | 7.3.2 |
Config/rextendr/version: | 0.3.1.9001 |
SystemRequirements: | Cargo (Rust's package manager), rustc |
NeedsCompilation: | yes |
Biarch: | true |
Depends: | R (≥ 4.2) |
Suggests: | rextendr (== 0.3.1), roxygen2, rstudioapi (≥ 0.7), devtools, pkgdown, desc, knitr, rmarkdown, testthat (≥ 3.0.0) |
URL: | https://rtergo.pagacz.io, https://github.com/kpagacz/tergo |
BugReports: | https://github.com/kpagacz/tergo/issues |
VignetteBuilder: | knitr |
Config/testthat/edition: | 3 |
Packaged: | 2025-04-11 16:02:33 UTC; kpagacz |
Author: | Konrad Pagacz [aut, cre], Maciej Nasinski [ctb], The authors of the dependency Rust crates [ctb] (see inst/AUTHORS file for details) |
Maintainer: | Konrad Pagacz <konrad.pagacz@gmail.com> |
Repository: | CRAN |
Date/Publication: | 2025-04-11 16:40:01 UTC |
A library to make your source code pretty.
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.
Author(s)
Maintainer: Konrad Pagacz konrad.pagacz@gmail.com
Other contributors:
Maciej Nasinski nasinski.maciej@gmail.com [contributor]
The authors of the dependency Rust crates (see inst/AUTHORS file for details) [contributor]
See Also
Useful links:
Report bugs at https://github.com/kpagacz/tergo/issues
Check for required RStudio API package
Description
Ensures the rstudioapi
package is available, as it is required for addin functionality.
Usage
check_rstudioapi()
Value
invisibly returns NULL
.
Format code
Description
Format code
Usage
format_code(source_code, configuration)
Arguments
source_code |
( |
Value
(character
) the formatted code
Parse the config file and return the configuration
Description
Parse the config file and return the configuration
Usage
get_config(path)
Arguments
path |
( |
Value
(list
)
Get the default configuration
Description
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.
Usage
get_default_config()
Details
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
.
Value
list
with the default configuration
Examples
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"
Check whether a path is in ignored paths
Description
Check whether a path is in ignored paths
Usage
is_in_ignored_paths(path, ignored_paths)
Value
(logical
) whether the path is in the ignored paths.
Style a package
Description
Style a package
Usage
style(config_file = "tergo.toml", configuration = list(), ...)
Arguments
config_file |
( |
configuration |
( |
... |
additional parameters to |
Details
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()
.
Value
No return value, called for side effects.
Examples
style()
style(config_file = "tergo.toml", configuration = list())
Style the active file (RStudio addin)
Description
Styles the currently active file in the RStudio editor and saves the formatted code.
Usage
style_active_file_addin()
Value
invisibly returns NULL
.
Style a file
Description
Style a file
Usage
style_file(file, configuration = list())
Arguments
file |
( |
configuration |
( |
Details
To see possible configuration options, see get_default_config()
.
Value
(logical
) whether the file was formatted successfully
or skipped. TRUE
- formatted successfully, FALSE
- skipped.
Examples
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 file internal
Description
Style a file internal
Usage
style_file_internal(file, configuration, ignored_paths)
Style a package
Description
Style a package
Usage
style_pkg(
path = ".",
config_file = "tergo.toml",
configuration = list(),
force = FALSE,
extensions = c(".R", ".r"),
verbose = interactive()
)
Arguments
path |
( |
config_file |
( |
configuration |
( |
force |
( |
extensions |
( |
verbose |
( |
Details
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()
.
Value
No return values, called for side effects.
Examples
style_pkg()
style_pkg(path = "./tergo", config_file = "custom_tergo.toml", verbose = TRUE)
Style the current package (RStudio addin)
Description
Automatically styles all R code in the current project/package using
style_pkg
. If not called within a project, it
defaults to the current working directory.
Usage
style_pkg_addin()
Value
invisibly returns NULL
.
Style the selected text (RStudio addin)
Description
Styles the selected text in the RStudio editor, replacing it with the formatted version.
Usage
style_selection_addin()
Value
invisibly returns NULL
.
Style text
Description
Style text
Usage
style_text(text, configuration = list())
Arguments
text |
( |
configuration |
( |
Details
This function is vectorized.
To see possible configuration options, see get_default_config()
.
Value
(character
) The text formatted as R code.
Examples
code <- "a+b"
styled <- style_text(code)
code <- c("a+b", "A<-7")
styled <- style_text(code)
Truncate the error message
Description
Truncate the error message
Usage
truncate_error(err)