[R-pkgs] formatR: farewell to ugly R code

From: Yihui Xie <xie_at_yihui.name>
Date: Tue, 13 Apr 2010 11:16:29 -0500


This is an announcement of the release of an R package 'formatR', which can help us format our R code to make it more human-readable. If you have ugly (I mean unformatted) R code like this:

 # rotation of the word "Animation"
# in a loop; change the angle and color
# step by step

for (i in 1:360) {
  # redraw the plot again and again
plot(1,ann=FALSE,type="n",axes=FALSE)
# rotate; use rainbow() colors

text(1,1,"Animation",srt=i,col=rainbow(360)[i],cex=7*i/360)
# pause for a while

Sys.sleep(0.01)}

There are no spaces, no appropriate indent... The package 'formatR' provides a GUI (by gWidgets) to make messy R code clean and tidy, e.g.

# rotation of the word 'Animation'
# in a loop; change the angle and color
# step by step

for (i in 1:360) {

   # redraw the plot again and again
   plot(1, ann = FALSE, type = "n", axes = FALSE)
   # rotate; use rainbow() colors
   text(1, 1, "Animation", srt = i, col = rainbow(360)[i],
       cex = 7 * i/360)
   # pause for a while
   Sys.sleep(0.01)

}

The usage is simple:

# formatR depends on RGtk+; will be installed automatically
# better use the latest version of R (>=2.10.1)
install.packages('formatR')
library(formatR)
# or formatR()

Screen-shots can be found here:
http://yihui.name/en/2010/04/formatr-farewell-to-ugly-r-code/

Regards,
Yihui

--
Yihui Xie <xieyihui_at_gmail.com>
Phone: 515-294-6609 Web: http://yihui.name
Department of Statistics, Iowa State University
3211 Snedecor Hall, Ames, IA

_______________________________________________
R-packages mailing list
R-packages_at_r-project.org
https://stat.ethz.ch/mailman/listinfo/r-packages
Received on Sat 17 Apr 2010 - 05:35:09 EST

This archive was generated by hypermail 2.2.0 : Sat 17 Apr 2010 - 05:40:02 EST