format_R_source_code {RFormatter}R Documentation

Formats R source code.

Description

format_R_source_code is very much based on formatR, but tries to improve it by heuristics. For example, spaces can be forced around the division operator /.

Usage

format_R_source_code(source, formatR_arguments = list(),
  remove_trailing_whitespace = TRUE, spaced_operators = c("/", "%%",
  "%/%", ":", "^"))

Arguments

source

String with source code to format. This not the filename of the source file.

formatR_arguments

List of arguments passed to formatR via its tidy_source.

remove_trailing_whitespace

Boolean: should horizontal whitespace at the end of lines be removed?

spaced_operators

Vector of strings with operators around which spaces are forced.

Value

String with formatted source code.

See Also

tidy_source

Examples


format_R_source_code("if (b) { f() }")
format_R_source_code("if (b) { f()\n\nf() }")
format_R_source_code("p = 2", list(arrow = TRUE, width.cutoff = 80))
format_R_source_code("(k/n)^x", spaced_operators = c("/"))

## Not run: 
format_R_source_code("f()", text = NULL)
format_R_source_code("f()", output = TRUE)

## End(Not run)


[Package RFormatter version 0.1.1 Index]