tidy.gui {formatR}R Documentation

A GUI to format R code

Description

Create a GUI (via GTK+ by default) to format R code.

Usage

tidy.gui(guiToolkit = "RGtk2")

Arguments

guiToolkit

the GUI toolkit to use

Details

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.

Value

the text widget is returned

Note

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.

References

https://github.com/yihui/formatR/wiki/ (screenshots)

See Also

tidy.source

Examples

## 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)

[Package formatR version 0.10 Index]