[R language] [Specification] Programming specification

Google publishes internal guidance on R language format specification

                                                 2016-09-06                                                 data science                                                 big data application                                                


The editor recently learned that Google has released internal guidelines for the format specification of the R language, which shows that the use of the R language has also been widely recognized within Google, and it is possible to expand the scale of use, so this guidance is released uniformly to standardize the future. code.

Of course, it is also possible that many friends who are accustomed to using R have been recruited, but they have not undergone strict training in format specifications, so there needs to be a unified guide.


There are 15 R programming specification guidelines released by Google this time, covering file name specification, variable name specification, code length of each line, indentation, use of curly braces, assignment expression, if else, non-use of semicolon, function definition , function annotations, etc. Let's take a closer look.


File and variable naming conventions

First , the name needs to be meaningful.

Second , for file names, underscores (_) are acceptable. But for variable names, do not use underscores or hyphens (-).

Variable name naming convention: all lowercase, then a dot (.) can be used as a separator.


Function name naming convention: capitalize the first letter, do not use a dot (.) as a separator.


Constant variable , the first letter must start with 'k'.



Code format specification

Line length : Do not exceed 80 characters per line.
Use of indentation: When indenting, use two spaces uniformly. Don't use 'tab' or mix 'tab' with spaces.
Use of spaces : Before and after all operator symbols (=, +, -, <-, etc.), spaces should be added. The comma (,) does not need to be added before, but must be added after the comma.

Use of curly braces : The opening curly brace ({) must immediately follow the previous line and cannot be the start of another line. In an if else, the opening curly brace must immediately follow the if else.


Assignment format specification
Use <- for assignment, not the equal sign '='. Use two equal signs (==) to determine whether the left and right values ​​are equal. This is very error prone.

There was a joke at the beginning of the year.


Come, zoom in on the code to see:

Did you see a typo?

There are some other specifications, which I won't list here. Interested friends can directly click 'read the original text'.

Then again, since Google has begun to promote R, does it mean that Python does not need to be learned?

of course not. Forgot to tell you, before R, Google has long issued a series of Python guidance and teaching courses, the link is here: https://developers.google.com/edu/python/ . Of course, it's simple.




read the original                                                                                       

Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=324487239&siteId=291194637