[ RDocumentation ](/)

Moon  [ ](https://github.com/datacamp/rdocumentation-2.0) [ Learn R
](https://www.datacamp.com/learn/r)

Search all packages and functions

[ base  (version  3.6.2  ) ](/packages/base/versions/3.6.2)

#  Syntax: Operator Syntax and Precedence

##  Description

Outlines  R  syntax and gives the precedence of operators.

##  Arguments

##  Details

The following unary and binary operators are defined. They are listed in
precedence groups, from highest to lowest.

` :: ::: ` |  access variables in a namespace   
---|---  
` $ @ ` |  component / slot extraction   
` [ [[ ` |  indexing   
` ^ ` |  exponentiation (right to left)   
` - + ` |  unary minus and plus   
` : ` |  sequence operator   
` %any% ` |  special operators (including ` %% ` and ` %/% ` )   
` * / ` |  multiply, divide   
` + - ` |  (binary) add, subtract   
` < > <= >= == != ` |  ordering and comparison   
` ! ` |  negation   
` & && ` |  and   
` | || ` |  or   
` ~ ` |  as in formulae   
` -> ->> ` |  rightwards assignment   
` <- <<- ` |  assignment (right to left)   
` = ` |  assignment (right to left)   
` ? ` |  help (unary and binary)   
  
Within an expression operators of equal precedence are evaluated from left to
right except where indicated. (Note that ` = ` is not necessarily an
operator.)

The binary operators ` :: ` , ` ::: ` , ` $ ` and ` @ ` require names or
string constants on the right hand side, and the first two also require them
on the left.

The links in the **See Also** section cover most other aspects of the basic
syntax.

##  References

Becker, R. A., Chambers, J. M. and Wilks, A. R. (1988) _The New S Language_ .
Wadsworth & Brooks/Cole.

##  See Also

` [ Arithmetic ](/link/Arithmetic?package=base&version=3.6.2) ` , ` [
Comparison ](/link/Comparison?package=base&version=3.6.2) ` , ` [ Control
](/link/Control?package=base&version=3.6.2) ` , ` [ Extract
](/link/Extract?package=base&version=3.6.2) ` , ` [ Logic
](/link/Logic?package=base&version=3.6.2) ` , ` [ NumericConstants
](/link/NumericConstants?package=base&version=3.6.2) ` , ` [ Paren
](/link/Paren?package=base&version=3.6.2) ` , ` [ Quotes
](/link/Quotes?package=base&version=3.6.2) ` , ` [ Reserved
](/link/Reserved?package=base&version=3.6.2) ` .

The ‘R Language Definition’ manual.

##  Examples

[ Run this code
](https://app.datacamp.com/workspace/preview?_tag=rdocs&rdocsPath=packages%2Fbase%2Fversions%2F3.6.2%2Ftopics%2FSyntax&utm_source=r-docs&utm_medium=docs&utm_term=Syntax&utm_content=run_example_in_workspace)

    
    
    # NOT RUN {
    ## 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):
    # }
    # NOT RUN {
    ## Consequently, this gives a ("non-catchable") error
     x <- y = 5  #->  Error in (x <- y) = 5 : ....
    # }
    

Run the code above in your browser using  [ DataCamp Workspace
](https://app.datacamp.com/workspace/preview?_tag=rdocs&rdocsPath=packages%2Fbase%2Fversions%2F3.6.2%2Ftopics%2FSyntax&utm_source=r-docs&utm_medium=docs&utm_term=Syntax&utm_content=run_example_in_workspace)

Powered by  [ DataCamp ](https://www.datacamp.com/)