R language code specification

Source: Internet
Author: User

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 ~~

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.