1. General rules
Avoid using attach
To write a function, use stop () as few as possible ()
Do not mix objects defining S3 and S4.
2. File Name
Add as much information as possible to files ended with. R in the file name, such
Good:
Predict_ad_revenue.r
Bad:
Foo. r
3. variable name and function naming rules
# Note: In the r environment, the Case sensitivity is
Variable:
Good:
AVG. clicks
Bad:
Avg_clicks, avgclicks
Function Name:
Good:
Calculateavgclicks
Bad:
Calculate_avg_clicks, calculateavgclicks
4. Character Interval
This may be the fastest way to make the Code look beautiful.
Good:
Tabprior <-table (DF [DF $ daysfromopt <0, "campaignid"])
Bad:
Tabprior <-table (DF [DF $ daysfromopt <0, "campaignid"])
Values, logical symbols, and comma separation are included.
# Use less = in R
In the function:
Good:
If (Debug)
Bad:
If (Debug)
5. Code Organization
The following information is required, especially for projects:
Copyright Notice
Author comment
File description, project purpose, input and output description
Source () and Library () Description
Function Definition
Others
6. Notes
Develop good comments habits
A single line comment starts with # And adds a space
A short comment requires two spaces after the code, and then #, add a space.
We recommend that you use Emacs + ESS again. Although I have been tossing for n times ~~