32

大多数编程语言对函数、参数、类等都有官方的命名约定。这里的官方意味着约定是由语言背后的组织发布的。

R有任何官方命名约定吗?

我知道之前在 stackoverflow 上讨论过命名约定和 R,但那是前一段时间了,我的问题不是“你喜欢什么命名约定?” 而是关注是否存在官方命名约定。

4

4 回答 4

16

R 开发人员页面包含来自 R-core的“R 统计系统或多或少最终确定的想法和计划”。它不包含有关命名约定的任何信息。简要看一下核心 R 代码将证实这一点。

于 2012-04-04T14:57:18.123 回答
13

R-core 有一个编码标准指南,但这不包括变量命名约定。

Bioconductor 还有一个编码标准指南,推荐使用 lowerCamelCase。

这里有这些和其他几个风格指南的链接

于 2012-04-04T15:03:53.033 回答
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.

于 2013-12-27T08:27:55.833 回答
2

正如其他人所回答的那样,没有官方的 R 编码风格,但如果您正在寻找一致的、经过深思熟虑的风格指南http://style.tidyverse.org/是一个不错的起点。它由流行的 tidyverse 系列软件包(dplyr、ggplot、tidyr 等)的作者编写,并被广泛的流行软件包使用。

作为 2017 年,这也是最流行的命名约定,根据 dwstu 的回答和提问者中引用的论文作者 Rasmus Bååth 在 userR2017 的演讲: https ://channel9.msdn.com/Events/user- international-R-User-conferences/user-International-R-User-2017-Conference/Room-302-Lightning-Talks(10:30 左右开始)

于 2017-07-15T09:08:43.590 回答