EVOLUTION-MANAGER
Edit File: Syntax.html
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd"><html xmlns="http://www.w3.org/1999/xhtml"><head><title>R: Operator Syntax and Precedence</title> <meta http-equiv="Content-Type" content="text/html; charset=utf-8" /> <link rel="stylesheet" type="text/css" href="R.css" /> </head><body> <table width="100%" summary="page for Syntax {base}"><tr><td>Syntax {base}</td><td style="text-align: right;">R Documentation</td></tr></table> <h2>Operator Syntax and Precedence</h2> <h3>Description</h3> <p>Outlines <span style="font-family: Courier New, Courier; color: #666666;"><b>R</b></span> syntax and gives the precedence of operators. </p> <h3>Details</h3> <p>The following unary and binary operators are defined. They are listed in precedence groups, from highest to lowest. </p> <table summary="Rd table"> <tr> <td style="text-align: left;"> <code>:: :::</code></td><td style="text-align: left;"> access variables in a namespace</td> </tr> <tr> <td style="text-align: left;"> <code>$ @</code></td><td style="text-align: left;"> component / slot extraction</td> </tr> <tr> <td style="text-align: left;"> <code>[ [[</code></td><td style="text-align: left;"> indexing</td> </tr> <tr> <td style="text-align: left;"> <code>^</code></td><td style="text-align: left;"> exponentiation (right to left)</td> </tr> <tr> <td style="text-align: left;"> <code>- +</code></td><td style="text-align: left;"> unary minus and plus</td> </tr> <tr> <td style="text-align: left;"> <code>:</code></td><td style="text-align: left;"> sequence operator</td> </tr> <tr> <td style="text-align: left;"> <code>%any%</code></td><td style="text-align: left;"> special operators (including <code>%%</code> and <code>%/%</code>)</td> </tr> <tr> <td style="text-align: left;"> <code>* /</code></td><td style="text-align: left;"> multiply, divide</td> </tr> <tr> <td style="text-align: left;"> <code>+ -</code></td><td style="text-align: left;"> (binary) add, subtract</td> </tr> <tr> <td style="text-align: left;"> <code>< > <= >= == !=</code></td><td style="text-align: left;"> ordering and comparison</td> </tr> <tr> <td style="text-align: left;"> <code>!</code></td><td style="text-align: left;"> negation</td> </tr> <tr> <td style="text-align: left;"> <code>& &&</code></td><td style="text-align: left;"> and</td> </tr> <tr> <td style="text-align: left;"> <code>| ||</code></td><td style="text-align: left;"> or</td> </tr> <tr> <td style="text-align: left;"> <code>~</code></td><td style="text-align: left;"> as in formulae</td> </tr> <tr> <td style="text-align: left;"> <code>-> ->></code></td><td style="text-align: left;"> rightwards assignment</td> </tr> <tr> <td style="text-align: left;"> <code><- <<-</code></td><td style="text-align: left;"> assignment (right to left)</td> </tr> <tr> <td style="text-align: left;"> <code>=</code></td><td style="text-align: left;"> assignment (right to left)</td> </tr> <tr> <td style="text-align: left;"> <code>?</code></td><td style="text-align: left;"> help (unary and binary)</td> </tr> <tr> <td style="text-align: left;"> </td> </tr> </table> <p>Within an expression operators of equal precedence are evaluated from left to right except where indicated. (Note that <code>=</code> is not necessarily an operator.) </p> <p>The binary operators <code>::</code>, <code>:::</code>, <code>$</code> and <code>@</code> require names or string constants on the right hand side, and the first two also require them on the left. </p> <p>The links in the <b>See Also</b> section cover most other aspects of the basic syntax. </p> <h3>Note</h3> <p>There are substantial precedence differences between <span style="font-family: Courier New, Courier; color: #666666;"><b>R</b></span> and S. In particular, in S <code>?</code> has the same precedence as (binary) <code>+ -</code> and <code>& && | ||</code> have equal precedence. </p> <h3>References</h3> <p>Becker, R. A., Chambers, J. M. and Wilks, A. R. (1988) <em>The New S Language</em>. Wadsworth & Brooks/Cole. </p> <h3>See Also</h3> <p><code><a href="Arithmetic.html">Arithmetic</a></code>, <code><a href="Comparison.html">Comparison</a></code>, <code><a href="Control.html">Control</a></code>, <code><a href="Extract.html">Extract</a></code>, <code><a href="Logic.html">Logic</a></code>, <code><a href="NumericConstants.html">NumericConstants</a></code>, <code><a href="Paren.html">Paren</a></code>, <code><a href="Quotes.html">Quotes</a></code>, <code><a href="Reserved.html">Reserved</a></code>. </p> <p>The ‘R Language Definition’ manual. </p> <h3>Examples</h3> <pre> ## Logical AND ("&&") has higher precedence than OR ("||"): TRUE || TRUE && FALSE # is the same as TRUE || (TRUE && FALSE) # and different from (TRUE || TRUE) && FALSE ## Special operators have higher precedence than "!" (logical NOT). ## You can use this for %in% : ! 1:10 %in% c(2, 3, 5, 7) # same as !(1:10 %in% c(2, 3, 5, 7)) ## but we strongly advise to use the "!( ... )" form in this case! ## '=' has lower precedence than '<-' ... so you should not mix them ## (and '<-' is considered better style anyway): ## Consequently, this gives a ("non-catchable") error x <- y = 5 #-> Error in (x <- y) = 5 : .... </pre> <hr /><div style="text-align: center;">[Package <em>base</em> version 3.6.0 <a href="00Index.html">Index</a>]</div> </body></html>