R Source Code Formatter

The R Formatter formats R source code. It is very much based on formatR, but tries to improve it by heuristics. For example, spaces can be forced around the division operator "/".


Build status CRAN version

The R Formatter formats R source code. It is very much based on formatR, but tries to improve it by heuristics. For example, spaces can be forced around the division operator /.

The following features are added to formatR.

  • Removing more trailing whitespace.
  • Adding spaces around more operators of your choice.

Installation

In R, run

Usage

Try

> RFormatter::format_R_source_code("if (b) { f() }")
> RFormatter::format_R_source_code("p = 2", list(arrow = TRUE))
> RFormatter::format_R_source_code("(k/n)^x", spaced_operators = c("/"))

Get more help with

> ?RFormatter::format_R_source_code

Command-Line Utility

To format a source file source.R via a command-line interface, do the following. Warning: the original file is overwritten, so better back it up first! Use this at your own risk. Run

$ Rscript [utility] source.R

where [utility] is the path given by

> system.file("exec", "utility.R", package = "RFormatter")

Related Projects

Have a look at Yihui Xie’s formatR.

News

News

RFormatter 0.1.1

  • Multiple operators with overlapping operands are now properly spaced (#1).

Reference manual

It appears you don't have a PDF plugin for this browser. You can click here to download the reference manual.

install.packages("RFormatter")

0.1.1 by Benjamin Fischer, 3 years ago


https://github.com/evolutics/RFormatter


Report a bug at https://github.com/evolutics/RFormatter/issues


Browse source code at https://github.com/cran/RFormatter


Authors: Benjamin Fischer [aut, cre]


Documentation:   PDF Manual  


GPL-3 license


Imports formatR

Suggests testthat


See at CRAN