tool to auto-format R code
Although ESS is a much better long-term solution, if you just have a quick formatting job, perhaps this package will help: http://yihui.name/en/?s=formatr.
Emacs with ESS does it exceedingly well -- and the default settings as recommended by R Core are in Section 7 R coding standards of the R Internals manual.