Posts Tagged ‘ tidy.source() ’

formatR: farewell to ugly R code

April 13, 2010
By
formatR: farewell to ugly R code

It is not uncommon to see messy R code which is almost not human-readable 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),cex=7*i/360) #

Read more »

R Tips in Stat 511

March 22, 2010
By
R Tips in Stat 511

Here are some (trivial) R tips in the course Stat 511. I’ll update this post till the semester is over. Formatting R Code Reading code is pain, but the well-formatted code might alleviate the pain a little bit. The function tidy.source() in the animation package can help us format our R code automatically. By default

Read more »

Enhanced tidy.source() (Preserve Some Comments)

March 31, 2009
By

After a few hours’ work, I modified the function tidy.source() in the animation package so that it can preserve complete comment lines. See the tidy.source() wiki page for example. tidy.source <- function(source = "clipboard", keep.comment = TRUE, keep.blank.line = FALSE, begin.comment, end.comment, ...) { # parse and deparse the code tidy.block = function(block.text)

Read more »