R+Supplement+-+3.5+-+Google_s+R+Style+Guide

R+Supplement+-+3.5+-+Google_s+R+Style+Guide - Google's R...

Info iconThis preview shows pages 1–3. Sign up to view the full content.

View Full Document Right Arrow Icon
R is a high-level programming language used primarily for statistical computing and graphics. The goal of the R Programming Style Guide is to make our R code easier to read, share, and verify. The rules below were designed in collaboration with the entire R user community at Google. File Names : end in .R 1. Identifiers : variable.name , FunctionName , kConstantName 2. Line Length : maximum 80 characters 3. Indentation : two spaces, no tabs 4. Spacing 5. Curly Braces : first on same line, last on own line 6. Assignment : use <- , not = 7. Semicolons : don't use them 8. General Layout and Ordering 9. Commenting Guidelines : all comments begin with # followed by a space; inline comments need two spaces before the # 10. Function Definitions and Calls 11. Function Documentation 12. Example Function 13. TODO Style : TODO(username) 14. attach : avoid using it 1. Functions : errors should be raised using stop() 2. Objects and Methods : avoid S4 objects and methods when possible; never mix S3 and S4 3. Notation and Naming 1. File Names File names should end in .R and, of course, be meaningful. GOOD: predict_ad_revenue.R BAD: foo.R Identifiers Don't use underscores ( _ ) or hyphens ( - ) in identifiers. Identifiers should be named according to the following conventions. Variable names should have all lower case letters and words separated with dots ( . ); function names have initial capital letters and no dots (CapWords); constants are named like functions but with an initial k . Google's R Style Guide http://google-styleguide.googlecode.com/svn/trunk/google-r-style.html 1 of 6 4/5/2011 10:11 AM
Background image of page 1

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon
variable.name GOOD: avg.clicks BAD: avg_Clicks , avgClicks 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 Syntax 2. Line Length The maximum line length is 80 characters. Indentation When indenting your code, use two spaces. Never use tabs or mix tabs and spaces. Exception: When a line break occurs inside parentheses, align the wrapped line with the first character inside the parenthesis. Spacing Place spaces around all binary operators ( = , + , - , <- , etc.). Exception: Spaces around
Background image of page 2
Image of page 3
This is the end of the preview. Sign up to access the rest of the document.

This note was uploaded on 10/18/2011 for the course POL POL 51 taught by Professor Haptosthal during the Fall '11 term at UC Davis.

Page1 / 6

R+Supplement+-+3.5+-+Google_s+R+Style+Guide - Google's R...

This preview shows document pages 1 - 3. Sign up to view the full document.

View Full Document Right Arrow Icon
Ask a homework question - tutors are online