Google's R Style Guide
User Manual:
Open the PDF directly: View PDF .
Page Count: 8
Download | |
Open PDF In Browser | View PDF |
Google's R Style Guide http://google-styleguide.googlecode.com/svn/trunk... Google's R Style Guide 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. Summary: R Style Rules 1. 2. 3. 4. 5. 6. 7. 8. 9. 10. 11. 12. 13. 14. File Names: end in .R Identifiers: variable.name, FunctionName, kConstantName Line Length: maximum 80 characters Indentation: two spaces, no tabs Spacing Curly Braces: first on same line, last on own line Assignment: use <-, not = Semicolons: don't use them General Layout and Ordering Commenting Guidelines: all comments begin with # followed by a space; inline comments need two spaces before the # Function Definitions and Calls Function Documentation Example Function TODO Style: TODO(username) Summary: R Language Rules 1. attach: avoid using it 2. Functions: errors should be raised using stop() 3. Objects and Methods: avoid S4 objects and methods when possible; never mix S3 and S4 1. Notation and Naming File Names File names should end in GOOD: predict_ad_revenue.R BAD: foo.R 1 of 8 .R and, of course, be meaningful. 08/29/2011 07:54 PM Google's R Style Guide http://google-styleguide.googlecode.com/svn/trunk... 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. 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 2. Syntax 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 ='s are optional when passing parameters in a function call. Do not place a space before a comma, but always place one after a comma. GOOD: tabPrior <- table(df[df$daysFromOpt < 0, "campaignid"]) 2 of 8 08/29/2011 07:54 PM Google's R Style Guide http://google-styleguide.googlecode.com/svn/trunk... total <- sum(x[, 1]) total <- sum(x[1, ]) BAD: tabPrior <- table(df[df$daysFromOpt<0, "campaignid"]) # Needs spaces around '<' tabPrior <- table(df[df$daysFromOpt < 0,"campaignid"]) # Needs a space after the comma tabPrior<- table(df[df$daysFromOpt < 0, "campaignid"]) # Needs a space before
Source Exif Data:File Type : PDF File Type Extension : pdf MIME Type : application/pdf PDF Version : 1.4 Linearized : No Page Count : 8 Creator : cairo 1.8.8 (http://cairographics.org) Producer : cairo 1.8.8 (http://cairographics.org)EXIF Metadata provided by EXIF.tools