R Programming Style Guide
For the code submitted for assignments, we would like you to follow these style rules from the Google R style guide. This style guide will be used when calculating the style grade for each of your programming assignments.
Naming conventions
Please follow a consistent naming convention for your variables. R is case sensitive, so we recommend using lower case for your variable names. You may use upper case for the first letter of a word when naming variables, functions or procedures or you may use an underscore to separate the words. Either way is fine as long as you are consistent.
In order to have your code read more like a natural language, we recommend that variable names should be nouns and function names should be verbs. Do your best to choose short descriptive names, we recognize that this can be difficult to do.
Indentation
Please indent the same number of blank characters for each level of your code associated with an if statement or a loop level. Please use at least 2 characters per level and at most 4 characters. You can set the number of indent characters within RStudio under the tools-> 'global options'->code panel. The default value for indentation is 2 characters; also RStudio associates the user's indentation definition with the TAB character.
Assignment operator
Use <- as the assignment operator.
Dealing with errors
Errors should be raised using stop().
Warnings can be viewed with warnings().
Commenting your code
For each file, function, procedure, complex data structure and complex line of code, provide a descriptive comment. Comments for a complex line of code or a complex data structure may be 1 line and be on the same line as the code. However, comments for an .R file, procedure or function should be a multiline comment. A comment starts with a #. For legibility, please follow the # by a space.
Comments for a function should follow the function's definition line. The comment should be indented. Function comments should consist of:
• a one-sentence description of the function
• a list of the function's arguments, denoted by Args
• With a textual description of each argument
• and its corresponding data type
• a description of the return value, denoted by Returns
The comments should be descriptive enough that a caller can use the function without reading any of the function's code.
Preparing for submission
It will take some time before you consistently follow these guidelines while writing code. So please, use the provided 'Reformat Code' option under the Code menu in RStudio in order to clean up your code before submitting.
For the code submitted for assignments, we would like you to follow these style rules from the Google R style guide. This style guide will be used when calculating the style grade for each of your programming assignments.
Naming conventions
Please follow a consistent naming convention for your variables. R is case sensitive, so we recommend using lower case for your variable names. You may use upper case for the first letter of a word when naming variables, functions or procedures or you may use an underscore to separate the words. Either way is fine as long as you are consistent.
In order to have your code read more like a natural language, we recommend that variable names should be nouns and function names should be verbs. Do your best to choose short descriptive names, we recognize that this can be difficult to do.
Indentation
Please indent the same number of blank characters for each level of your code associated with an if statement or a loop level. Please use at least 2 characters per level and at most 4 characters. You can set the number of indent characters within RStudio under the tools-> 'global options'->code panel. The default value for indentation is 2 characters; also RStudio associates the user's indentation definition with the TAB character.
Assignment operator
Use <- as the assignment operator.
Dealing with errors
Errors should be raised using stop().
Warnings can be viewed with warnings().
Commenting your code
For each file, function, procedure, complex data structure and complex line of code, provide a descriptive comment. Comments for a complex line of code or a complex data structure may be 1 line and be on the same line as the code. However, comments for an .R file, procedure or function should be a multiline comment. A comment starts with a #. For legibility, please follow the # by a space.
Comments for a function should follow the function's definition line. The comment should be indented. Function comments should consist of:
• a one-sentence description of the function
• a list of the function's arguments, denoted by Args
• With a textual description of each argument
• and its corresponding data type
• a description of the return value, denoted by Returns
The comments should be descriptive enough that a caller can use the function without reading any of the function's code.
Preparing for submission
It will take some time before you consistently follow these guidelines while writing code. So please, use the provided 'Reformat Code' option under the Code menu in RStudio in order to clean up your code before submitting.