| tidy.gui {formatR} | R Documentation |
Create a GUI (via GTK+ by default) to format R code.
tidy.gui(guiToolkit = "RGtk2")
guiToolkit |
the GUI toolkit to use |
This function calls tidy.source to format R
code. Spaces and indent will be added to the code
automatically.
We can either open an R source file or directly write R
code in the text widget. Click the convert button,
and the code will become tidy. See
tidy.source for more details.
the text widget is returned
By default, the interface is based on GTK+ (R package RGtk2), but other options (tcltk, rJava and Qt) are possible too. See the examples below. Note the Font button is only for the GTK+ interface.
https://github.com/yihui/formatR/wiki/ (screenshots)
## Not run:
library("gWidgetsRGtk2")
## a GUI will show up on loading if one of the gWidgets toolkit is
## present (e.g. via library(gWidgetsRGtk2))
library(formatR)
g = tidy.gui()
## we have control over the text widget, e.g. set or get the text
svalue(g) = c("# a single line of comments is preserved", "1+1",
"if(TRUE){", paste("x=1 ", "# inline comments!"), "}else{",
"x=2;print('Oh no... ask the right bracket to go away!')}",
"1*3 # another inline comment")
## click 'Convert' now, and see
cat(svalue(g), sep = "\n") # get its value
## tcl/tk interface: need gWidgetstcltk package
tidy.gui("tcltk")
## End(Not run)