| Title: | Format R Code with Arity |
| Version: | 0.1.0 |
| Description: | Provides R bindings to the deterministic, rule-based formatter from 'arity'. Format R source text or individual files using a style based on the tidyverse R style guide. |
| License: | MIT + file LICENSE |
| URL: | https://github.com/jolars/arity-r, https://arity.cc |
| BugReports: | https://github.com/jolars/arity-r/issues |
| Depends: | R (≥ 4.2) |
| Suggests: | testthat (≥ 3.0.0) |
| Config/rextendr/version: | 0.5.0 |
| Config/roxygen2/version: | 8.0.0 |
| Config/testthat/edition: | 3 |
| Encoding: | UTF-8 |
| Language: | en-US |
| SystemRequirements: | Cargo (Rust's package manager), rustc >= 1.89.0 |
| NeedsCompilation: | yes |
| Packaged: | 2026-09-01 19:07:21 UTC; jola |
| Author: | Johan Larsson |
| Maintainer: | Johan Larsson <johan@jolars.co> |
| Repository: | CRAN |
| Date/Publication: | 2026-09-25 22:30:09 UTC |
arity: Format R Code with Arity
Description
R bindings to the deterministic, rule-based formatter from arity.
Author(s)
Maintainer: Johan Larsson johan@jolars.co (ORCID) [copyright holder]
Authors:
Johan Larsson johan@jolars.co (ORCID) [copyright holder]
See Also
Useful links:
Report bugs at https://github.com/jolars/arity-r/issues
Format one UTF-8 file in place and report whether it changed.
Description
Format one UTF-8 file in place and report whether it changed.
Usage
format_file_native(
path,
line_width,
indent_width,
line_ending,
roxygen_markdown,
verify
)
Format R source code
Description
format_text() formats one R source string and returns the result.
format_file() formats one UTF-8 file in place and reports invisibly whether
its contents changed. Both functions use the formatter embedded in the
arity-formatter Rust crate; they do not invoke the arity CLI or discover an
arity.toml file.
Usage
format_text(
text,
line_width = 80L,
indent_width = 2L,
line_ending = c("auto", "lf", "crlf", "native"),
roxygen_markdown = FALSE,
verify = TRUE
)
format_file(
path,
line_width = 80L,
indent_width = 2L,
line_ending = c("auto", "lf", "crlf", "native"),
roxygen_markdown = FALSE,
verify = TRUE
)
Arguments
text |
A non-missing character scalar containing valid UTF-8 R source code. Strings with a declared encoding are converted to UTF-8. |
line_width |
Maximum output line width, from 1 through 1000. |
indent_width |
Number of spaces per indentation level, from 1 through 1000. |
line_ending |
Output line-ending policy. |
roxygen_markdown |
Whether roxygen blocks without an explicit |
verify |
Whether to verify syntax preservation, ordinary comment preservation, and idempotence after formatting. |
path |
A non-missing character scalar naming a UTF-8 file. The contents are treated as R source regardless of the file extension. |
Value
format_text() returns a character scalar. format_file() invisibly returns
TRUE when the file changed and FALSE otherwise.
Examples
format_text("x<-(1+2)*3^4\n")
path <- tempfile(fileext = ".R")
writeLines("x<-1", path)
format_file(path)
readLines(path)
unlink(path)
Format one R source string.
Description
Format one R source string.
Usage
format_text_native(
source,
line_width,
indent_width,
line_ending,
roxygen_markdown,
verify
)