反引号在R中起什么作用? [英] What do backticks do in R?

查看:373
本文介绍了反引号在R中起什么作用?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我试图了解反引号在R中的作用。

I'm trying to understand what backticks do in R.

据我所知,中没有对此进行解释吗? R的文档页面。

From what I can tell, this is not explained in the ?Quotes documentation page for R.

例如,在R控制台上:

"[["
# [1] "[["
`[[`
# .Primitive("[[")

似乎返回的等效项是:

get("[[")


推荐答案

一对反引号是引用保留或非法的名称或符号组合的一种方式。保留的单词是,如果是语言的一部分,而非法的单词则包含非语法组合,例如 t 。 R文档中将这两个类别(保留和非法)称为非语法名称

A pair of backticks is a way to refer to names or combinations of symbols that are otherwise reserved or illegal. Reserved are words like if are part of the language, while illegal includes non-syntactic combinations like c a t. These two categories, reserved and illegal, are referred to in R documentation as non-syntactic names.

因此,

`c a t` <- 1 # is valid R

> `+` # is equivalent to typing in a syntactic function name
function (e1, e2)  .Primitive("+")

正如评论者所提到的,?语录确实在名称和标识符下包含了一些反引号信息:

As a commenter mentioned, ?Quotes does contain some information on the backtick, under Names and Identifiers:


标识符由字母,数字和句点()组成。)和下划线。它们不能以数字开头,下划线或以数字开头的句点。保留字不是有效的标识符。

Identifiers consist of a sequence of letters, digits, the period (.) and the underscore. They must not start with a digit nor underscore, nor with a period followed by a digit. Reserved words are not valid identifiers.

字母的定义取决于当前的语言环境,但是只有ASCII数字才被视为数字。

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

此类标识符也称为语法名称,可以直接在R代码中使用。几乎总是可以使用其他名称,只要它们被引用即可。首选引号是反引号(`),而 deparse 通常会使用它,但是在许多情况下是单引号或双引号可以使用引号(因为字符常量通常会转换为名称)。可能需要反引号的一个地方是在公式中分隔变量名称:请参见公式

Such identifiers are also known as syntactic names and may be used directly in R code. Almost always, other names can be used provided they are quoted. The preferred quote is the backtick (`), and deparse will normally use it, but under many circumstances single or double quotes can be used (as a character constant will often be converted to a name). One place where backticks may be essential is to delimit variable names in formulae: see formula

这个散文有点难以解析。这意味着R要将标记解析为名称,必须为1)字母数字序列,句点和下划线,2)不是语言中的保留字。否则,要解析为名称,必须使用反引号。

This prose is a little hard to parse. What it means is that for R to parse a token as a name, it must be 1) a sequence of letters digits, the period and underscores, that 2) is not a reserved word in the language. Otherwise, to be parsed as a name, backticks must be used.

还可以查看?保留


引号外的保留字始终被解析为对描述中链接的对象的引用,因此不允许将它们用作语法名称(请参见 make.names )。可以将它们用作非语法名称,例如,在反引号内。

Reserved words outside quotes are always parsed to be references to the objects linked to in the 'Description', and hence they are not allowed as syntactic names (see make.names). They are allowed as non-syntactic names, e.g.inside backtick quotes.

此外,Advanced R还提供了一些如何使用反引号的示例在表达式环境功能

In addition, Advanced R has some examples of how backticks are used in expressions, environments, and functions.

这篇关于反引号在R中起什么作用?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆