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
Brian Lunergan
2010-Apr-18 11:15 UTC
[R] [R-pkgs] formatR: farewell to ugly R code... Problem with too old ver. of Gtk
Yihui Xie wrote:> 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/Interested in adding this package but when I tried to load it and its dependencies the system spit back that I didn't have the right version of Gtk. I'm running Ubuntu Linux 8.04 (Hardy Heron) with all the called for updates. I've looked in synaptic but I'm not an 'under the hood' type of user so I have no clue what to look for in there to find out what I have or even if it is possible to update. Oh yes, I'm running v2.10.1 of R. Is there any likely solution to this situation, or am I SOL because my Linux version is now simply too old? Regards... -- Brian Lunergan Nepean, Ontario Canada