Description Usage Arguments Value Note Author(s) References See Also Examples
This function returns reformatted source code; it tries to preserve blank
lines and comments, which is different with parse
and
deparse
. It can also replace =
with <-
where
=
means assignments, and reindent code by a specified number of spaces
(default is 4).
1 2 3 4 5 6 | tidy_source(source = "clipboard", comment = getOption("formatR.comment",
TRUE), blank = getOption("formatR.blank", TRUE),
arrow = getOption("formatR.arrow", FALSE),
brace.newline = getOption("formatR.brace.newline", FALSE),
indent = getOption("formatR.indent", 4), output = TRUE, text = NULL,
width.cutoff = getOption("width"), ...)
|
source |
a character string: location of the source code (default to be
the clipboard; this means we can copy the code to clipboard and use
|
comment |
whether to keep comments ( |
blank |
whether to keep blank lines ( |
arrow |
whether to replace the assign operator |
brace.newline |
whether to put the left brace |
indent |
number of spaces to indent the code (default 4) |
output |
output to the console or a file using |
text |
an alternative way to specify the input: if it is |
width.cutoff |
passed to |
... |
other arguments passed to |
A list with components
text.tidy |
the reformatted code as a character vector |
text.mask |
the code containing comments, which are masked in assignments or with the weird operator |
Be sure to read the reference to know other limitations.
Yihui Xie <http://yihui.name> with substantial contribution from Yixuan Qiu <http://yixuan.cos.name> and a very very very miniscule change from James Balamuta <http://thecoatlessprofessor.com> to enable a reverse equation clean.
http://yihui.name/formatR (an introduction to this package, with examples and further notes)
1 2 3 4 5 6 7 8 9 10 | messy = system.file("format", "messy.R", package = "formatR")
tidy_source(messy)
# if you've copied R code into the clipboard
if (interactive()) {
tidy_source("clipboard")
# write into clipboard again
tidy_source("clipboard", file = "clipboard")
}
|
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.