format_R_source_code: Formats R source code.

Description Usage Arguments Value See Also Examples

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

1
2
3
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

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
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)

evolutics/RFormatter documentation built on May 16, 2019, 9:40 a.m.