The standard answer is to use packages — see the Writing R Extensions manual as well as different tutorials on the web.
It gives you
- a quasi-automatic way to organize your code by topic
- strongly encourages you to write a help file, making you think about the interface
- a lot of sanity checks via
R CMD check
- a chance to add regression tests
- as well as a means for namespaces.
Just running source()
over code works for really short snippets. Everything else should be in a package — even if you do not plan to publish it as you can write internal packages for internal repositories.
As for the ‘how to edit’ part, the R Internals manual has excellent R coding standards in Section 6. Otherwise, I tend to use defaults in Emacs’ ESS mode.
Update 2008-Aug-13: David Smith just blogged about the Google R Style Guide.