mirror of
https://github.com/Stone-Red-Code/naming-convention.git
synced 2026-09-04 00:56:16 +02:00
Update README and R style guide
This commit is contained in:
@@ -8,16 +8,17 @@
|
|||||||
| Data Frame | PascalCase | 30 | No | df_ | No | No | df_[A-z]+ | df_AvgClicks |
|
| Data Frame | PascalCase | 30 | No | df_ | No | No | df_[A-z]+ | df_AvgClicks |
|
||||||
| Factor Variable Name | PascalCase | 30 | No | f | No | No | f[A-z]+ | fAvgClicks |
|
| Factor Variable Name | PascalCase | 30 | No | f | No | No | f[A-z]+ | fAvgClicks |
|
||||||
|
|
||||||
|
|
||||||
## Notation and Naming
|
## Notation and Naming
|
||||||
|
|
||||||
### File Names
|
### File Names
|
||||||
|
File names should end in uppercase `.R`, delimeter '\_', lowercase notation and, of course, be meaningful.
|
||||||
File names should end in .R, delimeter '\_', lowercase notation and, of course, be meaningful.
|
|
||||||
|
|
||||||
**GOOD:** predict\_ad\_revenue.R
|
**GOOD:** predict\_ad\_revenue.R
|
||||||
|
|
||||||
**BAD:** foo.R
|
**BAD:** foo.R
|
||||||
|
|
||||||
|
|
||||||
### Identifiers
|
### Identifiers
|
||||||
|
|
||||||
Don't use underscores ( _ ) or hyphens ( - ) in identifiers. Identifiers should be named according to the following conventions. Variable names have initial lower case letters. If variable name consists of several words, then they aren't separated, but all words except for the first one begin with capital letters. Function names are formed like variable names but with initial capital letter (FunctionName); constants are named like functions but with an initial k.
|
Don't use underscores ( _ ) or hyphens ( - ) in identifiers. Identifiers should be named according to the following conventions. Variable names have initial lower case letters. If variable name consists of several words, then they aren't separated, but all words except for the first one begin with capital letters. Function names are formed like variable names but with initial capital letter (FunctionName); constants are named like functions but with an initial k.
|
||||||
@@ -38,21 +39,19 @@ Don't use underscores ( _ ) or hyphens ( - ) in identifiers. Identifiers should
|
|||||||
*Exception: When creating a classed object, the function name (constructor) and class should match (e.g., lm).*
|
*Exception: When creating a classed object, the function name (constructor) and class should match (e.g., lm).*
|
||||||
- kConstantName
|
- kConstantName
|
||||||
|
|
||||||
|
|
||||||
## Syntax
|
## Syntax
|
||||||
|
|
||||||
### Line Length
|
### Line Length
|
||||||
|
|
||||||
The maximum line length is 80 characters.
|
The maximum line length is 80 characters.
|
||||||
|
|
||||||
### Indentation
|
### Indentation
|
||||||
|
|
||||||
When indenting your code, use two spaces. Never use tabs or mix tabs and spaces.
|
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.*
|
*Exception: When a line break occurs inside parentheses, align the wrapped line with the first character inside the parenthesis.*
|
||||||
|
|
||||||
### Spacing
|
### Spacing
|
||||||
|
Place spaces around all binary operators (=, +, -, <-, etc.).
|
||||||
Place spaces around all binary operators (=, +, -, <-, etc.).
|
|
||||||
|
|
||||||
*Exception: Spaces around ='s are optional when passing parameters in a function call.*
|
*Exception: Spaces around ='s are optional when passing parameters in a function call.*
|
||||||
|
|
||||||
@@ -64,6 +63,7 @@ df_TabPrior <- table(df[df$days.from.opt < 0, "campaign.id"])
|
|||||||
total <- sum(x[, 1])
|
total <- sum(x[, 1])
|
||||||
total <- sum(x[1, ])
|
total <- sum(x[1, ])
|
||||||
```
|
```
|
||||||
|
|
||||||
**BAD:**
|
**BAD:**
|
||||||
```
|
```
|
||||||
df_TabPrior <- table(df[df$days.from.opt<0, "campaign.id"]) # Needs spaces around '<'
|
df_TabPrior <- table(df[df$days.from.opt<0, "campaign.id"]) # Needs spaces around '<'
|
||||||
@@ -185,8 +185,8 @@ Do not terminate your lines with semicolons or use semicolons to put more than o
|
|||||||
|
|
||||||
Unit tests should go in a separate file named "originalfilename_test.R".
|
Unit tests should go in a separate file named "originalfilename_test.R".
|
||||||
|
|
||||||
### Commenting Guidelines
|
|
||||||
|
|
||||||
|
### Commenting Guidelines
|
||||||
Comment your code. Entire commented lines should begin with "#" and one space.
|
Comment your code. Entire commented lines should begin with "#" and one space.
|
||||||
|
|
||||||
Short comments can be placed after code preceded by two spaces, "#", and then one space.
|
Short comments can be placed after code preceded by two spaces, "#", and then one space.
|
||||||
@@ -198,8 +198,9 @@ hist(df$pct.spent,
|
|||||||
xlab = "Fraction of budget spent",
|
xlab = "Fraction of budget spent",
|
||||||
ylab = "Frequency (count of campaignids)")
|
ylab = "Frequency (count of campaignids)")
|
||||||
```
|
```
|
||||||
### Function Definitions and Calls
|
|
||||||
|
|
||||||
|
|
||||||
|
### Function Definitions and Calls
|
||||||
Function definitions should first list arguments without default values, followed by those with default values.
|
Function definitions should first list arguments without default values, followed by those with default values.
|
||||||
|
|
||||||
In both function definitions and function calls, multiple arguments per line are allowed; line breaks are only allowed between assignments.
|
In both function definitions and function calls, multiple arguments per line are allowed; line breaks are only allowed between assignments.
|
||||||
@@ -257,15 +258,14 @@ Use a consistent style for TODOs throughout your code.
|
|||||||
TODO(username): Explicit description of action to be taken
|
TODO(username): Explicit description of action to be taken
|
||||||
```
|
```
|
||||||
### Attach
|
### Attach
|
||||||
|
|
||||||
The possibilities for creating errors when using "attach" are numerous. Avoid it.
|
The possibilities for creating errors when using "attach" are numerous. Avoid it.
|
||||||
|
|
||||||
### Functions
|
|
||||||
|
|
||||||
|
### Functions
|
||||||
Errors should be raised using stop().
|
Errors should be raised using stop().
|
||||||
|
|
||||||
### Objects and Methods
|
|
||||||
|
|
||||||
|
### Objects and Methods
|
||||||
The S language has two object systems, S3 and S4, both of which are available in R. S3 methods are more interactive and flexible, whereas S4 methods are more formal and rigorous. (For an illustration of the two systems, see Thomas Lumley's "Programmer's Niche: A Simple Class, in S3 and S4" in R News 4/1, 2004, pgs. 33 - 36: http://cran.r-project.org/doc/Rnews/Rnews_2004-1.pdf.)
|
The S language has two object systems, S3 and S4, both of which are available in R. S3 methods are more interactive and flexible, whereas S4 methods are more formal and rigorous. (For an illustration of the two systems, see Thomas Lumley's "Programmer's Niche: A Simple Class, in S3 and S4" in R News 4/1, 2004, pgs. 33 - 36: http://cran.r-project.org/doc/Rnews/Rnews_2004-1.pdf.)
|
||||||
|
|
||||||
Use S3 objects and methods unless there is a strong reason to use S4 objects or methods. A primary justification for an S4 object would be to use objects directly in C++ code. A primary justification for an S4 generic/method would be to dispatch on two arguments.
|
Use S3 objects and methods unless there is a strong reason to use S4 objects or methods. A primary justification for an S4 object would be to use objects directly in C++ code. A primary justification for an S4 generic/method would be to dispatch on two arguments.
|
||||||
|
|||||||
@@ -1,14 +1,14 @@
|
|||||||
# Templates for naming convention
|
# Templates for naming convention
|
||||||
- [C# Coding Standards and Naming Conventions](C%23 Coding Standards and Naming Conventions.md)
|
- [C# Coding Standards and Naming Conventions](C%23%20Coding%20Standards%20and%20Naming%20Conventions.md)
|
||||||
- [Git Comment Convention](Git Comment Convention.md)
|
- [Git Comment Convention](Git%20Comment%20Convention.md)
|
||||||
- [JavaScript Name and Coding Conventions](JavaScript Name and Coding Conventions.md)
|
- [JavaScript Name and Coding Conventions](JavaScript%20Name%20and%20Coding%20Conventions.md)
|
||||||
- [Powershell name convention](Powershell.md)
|
- [Powershell name convention](Powershell.md)
|
||||||
- [R style guide and name convention](R style guide and name convention.md)
|
- [R style guide and name convention](R%20style%20uide%20and%20name%20convention.md)
|
||||||
- [SQL Server Name Convention](SQL Server Name Convention.md)
|
- [SQL Server Name Convention and T-SQL Programming Style](SQL%20Server%20Name%20Convention%20and%20T-SQL%20Programming%20Style.md)
|
||||||
|
|
||||||
## Usefull links for name conventions
|
## Usefull links for name conventions
|
||||||
- [MSDN C#]
|
- [NET Naming Guidelines]
|
||||||
- [MSDN ASP.NET MVC]
|
- [Framework Design Guidelines]
|
||||||
- [Google's R Style Guide]
|
- [Google's R Style Guide]
|
||||||
- [Google Python Style Guide]
|
- [Google Python Style Guide]
|
||||||
- [MSDN Powershell Style Guide]
|
- [MSDN Powershell Style Guide]
|
||||||
@@ -37,8 +37,8 @@
|
|||||||
- [Colin Gillespie’s R style guide]
|
- [Colin Gillespie’s R style guide]
|
||||||
- [Hadley Wickham’s style guide]
|
- [Hadley Wickham’s style guide]
|
||||||
|
|
||||||
[MSDN C#]:http://msdn.microsoft.com/en-us/library/xzf533w0%28v=vs.71%29.aspx
|
[NET Naming Guidelines]:https://docs.microsoft.com/en-us/dotnet/standard/design-guidelines/naming-guidelines
|
||||||
[MSDN ASP.NET MVC]:http://msdn.microsoft.com/en-us/library/ms229042.aspx
|
[Framework Design Guidelines]:https://docs.microsoft.com/en-us/dotnet/standard/design-guidelines/index
|
||||||
[Google's R Style Guide]:http://google-styleguide.googlecode.com/svn/trunk/Rguide.xml
|
[Google's R Style Guide]:http://google-styleguide.googlecode.com/svn/trunk/Rguide.xml
|
||||||
[Google Python Style Guide]:https://google-styleguide.googlecode.com/svn/trunk/pyguide.html
|
[Google Python Style Guide]:https://google-styleguide.googlecode.com/svn/trunk/pyguide.html
|
||||||
[MSDN Powershell Style Guide]:http://msdn.microsoft.com/en-us/library/dd878270%28v=vs.85%29.aspx
|
[MSDN Powershell Style Guide]:http://msdn.microsoft.com/en-us/library/dd878270%28v=vs.85%29.aspx
|
||||||
|
|||||||
Reference in New Issue
Block a user