yihui / formatR

Format R Code Automatically
https://yihui.org/formatr/
255 stars 52 forks source link

reindent R code without really parsing it? #12

Closed yihui closed 12 years ago

yihui commented 12 years ago

suggestion from Gabor Grothendieck; yes, it is safer and sounds less scary

see RStudio (daily build 0.95.186)

ramnathv commented 12 years ago

Yihui. I have a heavily refactored version of formatR, that implements in addition to the features you have, (a) reindentation to 2 spaces and (b) alignment of assignments. Let me post it on github, so that you can have a look at it.

yihui commented 12 years ago

Oh, that is really cool; I'd love to see the changes. Actually I've been longing for the alignment of assignments!

ramnathv commented 12 years ago

I have added the repository to github. https://github.com/ramnathv/styleR. You will notice that I have refactored your code by breaking it down into smaller chunks. I had to do this in order to add the new functionality. There are still several rough edges, but would be to get some feedback so that maybe in the future, some of this new functionality can be ported back to formatR. I have called the repository styleR, but that is purely to avoid confusion amongst users. All the ideas used are directly from formatR and I have attributed the same in the README file.

When you get a chance, test it and let me know what you think.

yihui commented 12 years ago

Man, you did exactly what I wished to do, e.g. I really wished I had used tidy_source instead of tidy.source(), but I have been hesitating on such changes since this may break other people's work. My programming style has changed a lot since my first few packages (learning from Hadley). I will take a look as soon as I've got time. Thanks a lot!

ramnathv commented 12 years ago

Well, my programming style has been influenced significantly by Hadley. If you get a chance, you should read the book Code Complete. It is the bible as far as programming style is concerned, and is extremely well written.