...

/

Naming Conventions

Naming Conventions

In this lesson we will learn naming convention in R.

R is a high-level programming language used primarily for statistical computing and graphics. The goal of the R Programming Style Guide is to make our R code easier to read, share, and verify. The rules below were designed in collaboration with the entire R user community at Google.

File Names

File names should end in .R and, of course, be meaningful.

Press + to interact
# GOOD
predict_ad_revenue.R
# BAD
foo # no extension
foo.R # meaningless name

Identifiers

Don’t use underscores ( _ ) or hyphens ( - ) in identifiers. Identifiers should be named according to the following conventions.

Variable names

The preferred form for variable names is all lower case letters and words separated with dots for example, variable.name, but variableName is also accepted.

Press + to interact
# GOOD
avg.clicks
# OK
avgClicks
#BAD
avg_Clicks

Function Names

Function names should be CamelCase. Use Capitalization of the first letter to separate words within a name, for example, FunctionName.

  • Make function names verbs.
Press + to interact
# GOOD
CalculateAvgClicks
# BAD
calculate_avg_clicks # use of underscores
calculateAvgClicks # first letter is lower case

Constant Names

Constants are named like functions but with an initial k, for example, kConstantName.

Press + to interact
# GOOD
kOne
# BAD
one