2016-03-25 11 views
13

मैं समझने के लिए बैकटिक आर में क्या कोशिश कर रहा हूँआर में बैकटिक्स क्या करते हैं?

मैं क्या कहता हूं,, इस आर

उदाहरण के लिए के लिए ?Quotes प्रलेखन पेज में नहीं समझाया गया है सकते हैं आर कंसोल पर से

:

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

यह के बराबर लौटने लगते हैं:

get("[[") 
+0

सहायता ("' ") – hrbrmstr

+1

'सहायता (" \ '")' सहायता ("\' ") 'के रूप में हो सकती है' वही दस्तावेज़ पृष्ठ 'के रूप में लाता है?उद्धरण', जो पूरी तरह स्पष्ट नहीं था – Megatron

+0

क्यू में चूक गया। क्षमा याचना। लेकिन यह एक सभ्य स्पष्टीकरण है जो यह करता है। – hrbrmstr

उत्तर

8

का उपयोग कर बैकटिक्स की एक जोड़ी उन नामों या संयोजनों के संयोजनों का संदर्भ देने का एक तरीका है जो अन्यथा आरक्षित या अवैध हैं। आरक्षित शब्द if भाषा का हिस्सा हैं, जबकि अवैध गैर-वाक्य रचनात्मक संयोजन जैसे c a t शामिल हैं। इन दो श्रेणियों, आरक्षित और अवैध, आर प्रलेखन में non-syntactic names के रूप में संदर्भित हैं।

इस प्रकार,

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

और

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

एक टिप्पणीकार उल्लेख किया है, ?Quotes बैकटिक पर कुछ जानकारी होती है, 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. 

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

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’. 

इस गद्य के तहत एक छोटे से कठिन है पार्स करने के लिए। इसका अर्थ यह है कि आर के लिए एक टोकन को नाम के रूप में पार्स करने के लिए, यह 1 होना चाहिए) अक्षरों के अंक, अवधि और अंडरस्कोर का अनुक्रम, 2) भाषा में एक आरक्षित शब्द नहीं है। अन्यथा, नाम के रूप में पार्स किया जाना चाहिए, बैकटिक्स का उपयोग किया जाना चाहिए।

इसके अलावा बाहर की जाँच ?Reserved:

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. 

इसके अलावा, उन्नत अनुसंधान कैसे बैकटिक में expressions, environments, और functions उपयोग किया जाता है के कुछ उदाहरण हैं।

5

वे शब्दशः के बराबर हैं। उदाहरण के लिए ... इस प्रयास करें:

df <- data.frame(20a=c(1,2),b=c(3,4)) 

त्रुटि देता है

df <- data.frame(`20a`=c(1,2),b=c(3,4)) 

त्रुटि

3

यहाँ नहीं देता अनुचित शब्दावली का उपयोग करते हुए एक अधूरी जवाब है: बैकटिक आर को इंगित कर सकते हैं कि आप कर रहे हैं एक गैर मानक तरीके से एक समारोह का उपयोग कर। उदाहरण के लिए, यहाँ [[ का एक प्रयोग है, सूची subsetting समारोह:

temp <- list("a"=1:10, "b"=rnorm(5)) 

निकालने तत्व एक है, हमेशा की तरह

temp[[1]] 

निकालने तत्व एक [[ समारोह

`[[`(temp,1) 
संबंधित मुद्दे