04 May 2014

#R: coding style



Here's a resume of R coding style guidelines from various sources. Something to keep in my mind also.

"...11. When summarizing the results of your output, I recommend working with "display()" (from the arm package) rather than "summary()". The summary() function always seems to give a lot of crap, and we've tried to be cleaner and more focused with display(). One option is to set up functions for both so that users can typically use display(), with some extra information in summary()." ...

...Use a system to name a function...
... Don't use underscores ( _ ) or hyphens ( - ) in identifiers. Identifiers should be named according to the following conventions. The preferred form for variable names is all lower case letters and words separated with dots (variable.name), but variableName is also accepted; function names have initial capital letters and no dots (FunctionName); constants are named like functions but with an initial k... 
Here are few examples:
    • variable.name is preferred 
    • variableName is accepted
    • GOOD: avg.clicks
    • OK: avgClicks
    • BAD: avg_Clicks
    • FunctionName 
    • GOOD: CalculateAvgClicks
    • BAD: calculate_avg_clicks calculateAvgClicks
    • Make function names verbs.
    • Exception: When creating a classed object, the function name (constructor) and class should match (e.g., lm).
    • kConstantName
    • ..."
Happy coding :-)

{@dasaptaerwin}

No comments: