| assignOps {base} | R Documentation |
Assignment Operators
Description
Assign a value to a name.
Usage
x <- valuex <<- valuevalue -> xvalue ->> xx = valueArguments
x | a variable name (possibly quoted). |
value | a value to be assigned to |
Details
There are three different assignment operators: two of themhave leftwards and rightwards forms.
The operators<- and= assign into the environment inwhich they are evaluated. The operator<- can be usedanywhere, whereas the operator= is only allowed at the toplevel (e.g., in the complete expression typed at the command prompt)or as one of the subexpressions in a braced list of expressions.
The operators<<- and->> are normally only used infunctions, and cause a search to be made through parent environmentsfor an existing definition of the variable being assigned. If sucha variable is found (and its binding is not locked) then its valueis redefined, otherwise assignment takes place in the globalenvironment. Note that their semantics differ from that in the Slanguage, but are useful in conjunction with the scoping rules ofR. SeeThe R Language Definition for further details and examples.
In all the assignment operator expressions,x can be a nameor an expression defining a part of an object to be replaced (e.g.,z[[1]]). A syntactic name does not need to be quoted,though it can be (preferably bybackticks).
The leftwards forms of assignment<- = <<- group right to left,the other from left to right.
Value
value. Thus one can usea <- b <- c <- 6.
References
Becker R. A., Chambers J. M., Wilks A. R. (1988).The New S Language.Chapman and Hall/CRC, London.ISBN 053409192X.
Chambers J. M. (1998).Programming with Data.Springer, New York.ISBN 978-0-387-98503-9. (for=).
See Also
assign (and its inverseget),for “subassignment” such asx[i] <- v,see[<-; further,environment.