34

Most programming languages have official naming conventions for functions, parameters, classes, etc. Official here means that the conventions are issued by the organization behind the language.

Are there any official naming conventions for R?

I'm aware that naming conventions and R have been discussed before on stackoverflow, but that was some time ago and my question is not "what naming convention do you prefer?" but rather concerns whether official naming conventions exist.

Community
  • 1
  • 1
Rasmus Bååth
  • 4,827
  • 4
  • 29
  • 29

4 Answers4

16

The R Developer Page contains "more or less finalized ideas and plans for the R statistical system" from R-core. It does not contain any information about naming conventions. A brief look at the core R code will confirm this.

Joshua Ulrich
  • 173,410
  • 32
  • 338
  • 418
13

R-core have a coding standards guide, but this does not include variable naming conventions.

Bioconductor also has a coding standards guide, which recommends lowerCamelCase.

There are links to those and several other style-guides here.

ABCD
  • 7,914
  • 9
  • 54
  • 90
Richie Cotton
  • 118,240
  • 47
  • 247
  • 360
8

Check out "The State of Naming Conventions in R" for a good discussion on the topic!

I would like to quote the following:

Both the CRAN data and the style guides show that there is no consensus regarding naming conventions in R and this it likely to continue as naming conventions, to a large degree, are a matter of taste and habit.

What is most important, however, is to keep a consistent naming convention style within your code base, whether you are working on a personal project or developing a package.

Community
  • 1
  • 1
dwstu
  • 839
  • 10
  • 12
  • 3
    I actually wrote it myself after having asked this question :) Thank you for highlighting it! – Rasmus Bååth Dec 27 '13 at 12:01
  • Oh that's right @Rasmus Bååth. I just noticed the author of the _R Journal_ article is actually you. Anyway, it is a good piece :) – dwstu Dec 27 '13 at 15:13
2

As other people have answered, there is no official R coding style, but if you are looking for a consistent, well thought out style guide http://style.tidyverse.org/ is a good place to start. It was written by the author of the popular tidyverse family of packages (dplyr, ggplot, tidyr, and many more) and is used by a wide range of popular packages.

As 2017 this is also the most popular naming convention, according to the useR2017 talk by Rasmus Bååth, author of the paper cited in dwstu 's answer and asker of this question: https://channel9.msdn.com/Events/useR-international-R-User-conferences/useR-International-R-User-2017-Conference/Room-302-Lightning-Talks (starts around 10:30)

Stefan F
  • 2,573
  • 1
  • 17
  • 19
  • 1
    That is not the official naming convention of R, because there are none. That's a tidyverse style guide, something completely different. – Joris Meys Jul 15 '17 at 09:15
  • I never stated that it is, I just wrote that it seems to be the most popular naming convention nowadays. However, I updated my answer to make that more explicit. – Stefan F Jul 15 '17 at 13:10
  • 1
    You didn't, but OP asked for an official naming convention and the correct answer is "there is none". BTW, the tidyverse convention seems the most popular if you are a vivid tidyverse user, but R is far larger than that. Shiny and related packages for example don't use the tidyverse underscore notation, but use camelCase. Most Bioconductor packages use camelCase. And I personally sometimes still use the dot notation, especially when constructing test functions like `is.foo` or conversions like `as.foo`. Simply because that's how R did it the past 17 years. – Joris Meys Jul 15 '17 at 13:16
  • I mainly wrote my answer because someone linked a paper above that states camelCase is the most popular naming convention. That paper is from 2012 and according to a recent talk by the author of the paper that is no longer true (likely due to the popularity of tidyverse packages). The paper (and the updated data from the talk) is based on packages available from CRAN. – Stefan F Jul 15 '17 at 13:19