Syntax.Rd 3.09 KB
Newer Older
Radford Neal's avatar
Radford Neal committed
1 2
% File src/library/base/man/Syntax.Rd
% Part of the R package, http://www.R-project.org
3
% Copyright 1995-2011 R Core Team
Radford Neal's avatar
Radford Neal committed
4
% Modifications for pqR Copyright (c) 2016, 2018 Radford M. Neal.
Radford Neal's avatar
Radford Neal committed
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}{
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's avatar
Radford Neal committed
20
    \code{^}\tab exponentiation (right to left)\cr
21
    \code{-} \code{+}\tab unary minus and plus\cr
Radford Neal's avatar
Radford Neal committed
22
    \code{:}\tab sequence operator\cr
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
27
    \code{!} \code{!!}\tab (binary) string concatenation\cr
28 29
    \code{<} \code{>} \code{<=} \code{>=} \code{==} \code{!=}\tab 
             ordering and comparison (no ordering)\cr
30
    \code{!}\tab (unary) negation \cr
31 32
    \code{&} \code{&&}\tab and\cr
    \code{|} \code{||}\tab or\cr
33
    \code{~}\tab (unary and binary) as in formulae\cr
34
    \code{->} \code{->>}\tab rightwards assignment\cr
Radford Neal's avatar
Radford Neal committed
35
    \code{=}\tab assignment (right to left)\cr
36
    \code{<-} \code{<<-}\tab assignment (right to left)\cr
Radford Neal's avatar
Radford Neal committed
37 38 39
    \code{?}\tab help (unary and binary)\cr
  }
  Within an expression operators of equal precedence are evaluated
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{a<b<c}).
Radford Neal's avatar
Radford Neal committed
44

Radford Neal's avatar
Radford Neal committed
45 46 47 48
  The binary operators \code{::}, \code{:::}, \code{$} and \code{@} require
  names or string constants on the right hand side, and the first two
  also require them on the left.

49 50 51 52 53
  Language elements such as \code{if} are effectively lower
  precedence than all of these operators.  For example, \code{if (a>0)
  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's avatar
Radford Neal committed
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
59
  particular, in S \code{?} has the same precedence as (binary) \code{+}
Radford Neal's avatar
Radford Neal committed
60
  and \code{-} and \code{&}, \code{&&}, \code{|}, and \code{||} have 
61
  equal precedence.
Radford Neal's avatar
Radford Neal committed
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}