什么构成 R 中的有效符号(标识符)

What constitutes a valid symbol (identifier) in R

我找不到该语言的规范...

请注意,我要的是正确答案,例如像 this,因为我自己很容易想出一个简单但可能是错误的近似值,例如 [[:alpha:]._][\w._]*

documentation for make.names()

A syntactically valid name consists of letters, numbers and the dot or underline characters and starts with a letter or the dot not followed by a number. Names such as ".2way" are not valid, and neither are the reserved words.

The definition of a letter depends on the current locale, but only ASCII digits are considered to be digits.

@Roland 指出这一段 R language definition:

10.3.2 Identifiers

Identifiers consist of a sequence of letters, digits, the period (‘.’) and the underscore. They must not start with a digit or an underscore, or with a period followed by a digit.

The definition of a letter depends on the current locale: the precise set of characters allowed is given by the C expression (isalnum(c) || c == ‘.’ || c == ‘_’) and will include accented letters in many Western European locales.

Notice that identifiers starting with a period are not by default listed by the ls function and that ‘...’ and ‘..1’, ‘..2’, etc. are special.

Notice also that objects can have names that are not identifiers. These are generally accessed via get and assign, although they can also be represented by text strings in some limited circumstances when there is no ambiguity (e.g. "x" <- 1). As get and assign are not restricted to names that are identifiers they do not recognise subscripting operators or replacement functions.

规则似乎允许“摩尔斯编码”:

> .__ <- 1
> ._._. <- 2
> .__ + ._._.
[1] 3