Syntax.Rd 3.09 KB
 Radford Neal committed May 18, 2013 1 2 % File src/library/base/man/Syntax.Rd % Part of the R package, http://www.R-project.org  Radford Neal committed Aug 26, 2016 3 % Copyright 1995-2011 R Core Team  Radford Neal committed Sep 09, 2018 4 % Modifications for pqR Copyright (c) 2016, 2018 Radford M. Neal.  Radford Neal committed May 18, 2013 5 6 7 8 9 10 11 12 13 14 15 16 % Distributed under GPL 2 or later \name{Syntax} \alias{Syntax} \title{Operator Syntax and Precedence} \description{ Outlines \R syntax and gives the precedence of operators } \details{ The following unary and binary operators are defined. They are listed in precedence groups, from highest to lowest. \tabular{ll}{  Radford Neal committed Sep 09, 2018 17 18 19  \code{::} \code{:::}\tab access variables in a namespace\cr \code{\$} \code{@}\tab component / slot extraction\cr \code{[} \code{[[}\tab indexing\cr  Radford Neal committed May 18, 2013 20  \code{^}\tab exponentiation (right to left)\cr  Radford Neal committed Sep 09, 2018 21  \code{-} \code{+}\tab unary minus and plus\cr  Radford Neal committed May 18, 2013 22  \code{:}\tab sequence operator\cr  Radford Neal committed Sep 09, 2018 23 24 25 26  \code{\%op\%}\tab special operators (includes \code{\%\%} \code{\%/\%})\cr \code{*} \code{/}\tab multiply, divide\cr \code{+} \code{-}\tab (binary) add, subtract\cr \code{..}\tab upward sequence operator (no ordering)\cr  Radford Neal committed Oct 08, 2018 27  \code{!} \code{!!}\tab (binary) string concatenation\cr  Radford Neal committed Sep 09, 2018 28 29  \code{<} \code{>} \code{<=} \code{>=} \code{==} \code{!=}\tab ordering and comparison (no ordering)\cr  Radford Neal committed Oct 08, 2018 30  \code{!}\tab (unary) negation \cr  Radford Neal committed Sep 09, 2018 31 32  \code{&} \code{&&}\tab and\cr \code{|} \code{||}\tab or\cr  Radford Neal committed Sep 27, 2015 33  \code{~}\tab (unary and binary) as in formulae\cr  Radford Neal committed Sep 09, 2018 34  \code{->} \code{->>}\tab rightwards assignment\cr  Radford Neal committed May 18, 2013 35  \code{=}\tab assignment (right to left)\cr  Radford Neal committed Sep 09, 2018 36  \code{<-} \code{<<-}\tab assignment (right to left)\cr  Radford Neal committed May 18, 2013 37 38 39  \code{?}\tab help (unary and binary)\cr } Within an expression operators of equal precedence are evaluated  Radford Neal committed Sep 27, 2015 40 41 42 43  from left to right (eg, \code{a/b/c} means \code{(a/b)/c}), except if right to left evaluation is specified above (eg, \code{a^b^c} means \code{a^(b^c)}), or no ordering is specified above, so combining them without parentheses is illegal (eg, \code{a0) a else 2 * a} means the same as \code{if (a>0) a else (2 * a)}, which is not the same as \code{(if (a>0) a else 2) * a}.  Radford Neal committed May 18, 2013 54 55 56 57 58  The links in the \bold{See Also} section cover most other aspects of the basic syntax. } \note{ There are substantial precedence differences between \R and S. In  Radford Neal committed Sep 09, 2018 59  particular, in S \code{?} has the same precedence as (binary) \code{+}  Radford Neal committed Sep 19, 2018 60  and \code{-} and \code{&}, \code{&&}, \code{|}, and \code{||} have  Radford Neal committed Sep 09, 2018 61  equal precedence.  Radford Neal committed May 18, 2013 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 } \references{ Becker, R. A., Chambers, J. M. and Wilks, A. R. (1988) \emph{The New S Language}. Wadsworth & Brooks/Cole. } \seealso{ \code{\link{Arithmetic}}, \code{\link{Comparison}}, \code{\link{Control}}, \code{\link{Extract}}, \code{\link{Logic}}, \code{\link{NumericConstants}}, \code{\link{Paren}}, \code{\link{Quotes}}, \code{\link{Reserved}}. The \emph{R Language Definition} manual. } \keyword{documentation} \keyword{programming}