Learn R Programming

formatR (version 0.10)

tidy.gui: 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

Value

  • the text widget is returned

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.

References

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

See Also

tidy.source

Examples

Run this code
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")

Run the code above in your browser using DataLab