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.
# GOODpredict_ad_revenue.R# BADfoo # no extensionfoo.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.
# GOODavg.clicks# OKavgClicks#BADavg_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.
# GOODCalculateAvgClicks# BADcalculate_avg_clicks # use of underscorescalculateAvgClicks # first letter is lower case
Constant Names
Constants are named like functions but with an initial k
, for example, kConstantName
.
# GOODkOne# BADone