rformat_dir

Format R Files in Directory

Description

Format all R files in a directory.

Usage

1rformat_dir(
2  path = ".",
3  recursive = TRUE,
4  dry_run = FALSE,
5  indent = 4L,
6  wrap = "paren",
7  expand_if = FALSE,
8  brace_style = "kr"
9)

Arguments

  • path: Path to directory.
  • recursive: If TRUE, process subdirectories.
  • dry_run: If TRUE, report changes without writing.
  • indent: Indentation per level: integer for spaces (default 4), or character string for literal indent (e.g., "\t\t" for vintage R Core style).
  • wrap: Continuation style for long function signatures: "paren" (default) aligns to opening parenthesis, "fixed" uses 8-space indent.
  • expand_if: Expand inline if-else to multi-line (default FALSE).
  • brace_style: Brace placement for function definitions: "kr" (default) puts opening brace on same line as ) {, "allman" puts it on a new line.

Value

Invisibly returns vector of modified file paths.

Examples

1# Format all R files in a directory (dry run)
2d <- tempfile()
3dir.create(d)
4writeLines("x<-1", file.path(d, "test.R"))
5rformat_dir(d, dry_run = TRUE)
6
7# Format and overwrite
8rformat_dir(d)
9unlink(d, recursive = TRUE)