# Styling with tergo

    library(tergo)

# Get Started with `tergo`

`tergo` is a lightning-fast R code formatter powered by Rust, designed for developers who prioritize speed and efficiency. Whether you’re optimizing CI pipelines or building responsive developer tools, `tergo` reformats R code in milliseconds.

## Installation

### Method 1: From R-Universe (Recommended for Most Users)

No Rust tooling required. Binaries are pre-built:

    install.packages('tergo', repos = c(
      'https://kpagacz.r-universe.dev',
      'https://cloud.r-project.org'
    ))

### Method 2: From GitHub Sources (For Advanced Users)

Requires Rust toolchain:

    if (!require(remotes)) install.packages("remotes")
    remotes::install_github("kpagacz/tergo@latest", subdir = "antidotum/tergo")

## Basic Usage

Style your entire R package:

    tergo::style()  # Run in package root directory

Style specific files/directories:

    tergo::style("path/to/your-script.R")
    tergo::style(c("dir1/", "dir2/"))

## Configuration Options

Customize formatting via `tergo.toml` in your package root or through function arguments.

### Example `tergo.toml`

    indent = 4
    line_length = 80
    embracing_op_no_nl = false
    function_line_breaks = "double"

### Inline Configuration

Override settings programmatically:

    tergo::style(config = list(
      indent = 4,
      allow_nl_after_assignment = TRUE
    ))

### Full Configuration Reference

Option | Type | Default | Description
--- | --- | --- | ---
`indent` | integer | 2 | Spaces per indent level
`line_length` | integer | 120 | Maximum line length before wrapping
`embracing_op_no_nl` | boolean | TRUE | Remove line breaks in `{{ }}` (ref)
`allow_nl_after_assignment` | boolean | FALSE | Permit line breaks after `=`, `<-`, `:=`
`space_before_complex_rhs_in_formula` | boolean | TRUE | Add space before complex RHS in formulas (ref)
`strip_suffix_whitespace_in_function_defs` | boolean | TRUE | Trim trailing whitespace in functions
`function_line_breaks` | string | “hanging” | `"single"`/`"double"`/`"hanging"` function argument formatting (ref)
`insert_newline_in_quote_call` | boolean | TRUE | Add newlines in long `quote()` calls

## Why Choose `tergo`?

- Blazing Fast: Formats large codebases 100-1000x faster than alternatives
- CI-Friendly: Reduces CI runtime/costs by orders of magnitude
- Low-Config Efficiency: Sensible defaults with focused customization
- Native Performance: Rust core ensures consistent speed regardless of input size

## Advanced Usage

### Benchmarking

Verify performance claims using included benchmarks:

    source(system.file("bench.R", package = "tergo"))

### Project-Specific Configs

Maintain different `.toml` files for multiple projects:

    tergo::style(config = "path/to/alternate.toml")

Next Steps:
• Run `?tergo::style` for detailed function documentation
• Visit GitHub repository for issue tracking
• Experiment with different `.toml` configurations to match your team’s style guide ```