[R] R programming style
Roland Rau
roland.rproject at gmail.com
Mon Feb 11 16:19:54 CET 2008
Hi,
I think using Emacs+ESS [1,2] is always a good starting point for a
clear layout with consistent and meaningful indentation.
I don't know how other people think about it, but in my opinion,
"Elements of Programming Style" by Kernighan and Plauger is still an
interesting read -- although their programs are either Fortran or PL/1
and the book itself is 30 years or old. Of course, I am not always
successful but at least I try to incorporate their 'mantras':
- write clearly, don't be too clever [3]
- say what you mean, simply and directly
- use library functions
- write clearly -- don't sacrifice clarity for "efficiency"
- let the machine do the dirty work
- parenthesize to avoid ambiguity
- 10.0 times 0.1 is hardly ever 1.0
- ...
I hope this helps?
Best,
Roland
[1] http://www.gnu.org/software/emacs/
[2] http://ess.r-project.org/
[3] I guess this is what Kernighan meant in his famous(?) quote:
"Everyone knows that debugging is twice as hard as writing a program in
the first place. So if you're as clever as you can be when you write it,
how will you ever debug it?"
(http://en.wikiquote.org/wiki/Brian_W._Kernighan )
David Scott wrote:
> I am aware of one (unofficial) guide to style for R programming:
> http://www1.maths.lth.se/help/R/RCC/
> from Henrik Bengtsson.
>
> Can anyone provide further pointers to good style?
>
> Views on Bengtsson's ideas would interest me as well.
>
> David Scott
>
>
>
> _________________________________________________________________
> David Scott Department of Statistics, Tamaki Campus
> The University of Auckland, PB 92019
> Auckland 1142, NEW ZEALAND
> Phone: +64 9 373 7599 ext 86830 Fax: +64 9 373 7000
> Email: d.scott at auckland.ac.nz
>
> Graduate Officer, Department of Statistics
> Director of Consulting, Department of Statistics
>
> ______________________________________________
> R-help at r-project.org mailing list
> https://stat.ethz.ch/mailman/listinfo/r-help
> PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
> and provide commented, minimal, self-contained, reproducible code.
>
More information about the R-help
mailing list