colon-equals: Enhanced assignment to overwrite or grow objects

Description Usage Arguments Details Examples

Description

Use .. on the right hand side as a shorthand for the left hand side

Usage

1
":="(e1, e2)

Arguments

e1

left hand side

e2

right handside

Details

:= is **NOT** meant to be a complete replacement of the '<-' operator, it's meant to be explicit about growing an object or overwriting it using its previous value, avoid repeating a variable name, and saving keystrokes.

It is slightly slower than the standard assignment operator (though we're speaking microseconds). This should not distract the user from the fact that growing an object is often inefficient, especially in a loop.

:= can in principle be used several times in a statement like z <- (x := .. + 1) + (y:= .. +1) but it never makes sense to use it := several times in an assignment such as x := (y := .. + 2) as all the .. will be replaced by the name of the variable on the lhs of the first evaluated := in any case.

Examples

1
2
3
4
5
6
7
x <- 1
x := .. + 1
x

x <- factor(letters[1:3])
levels(x) := c(.., "level4")
x

Example output

[1] 2
[1] a b c
Levels: a b c level4

dotdot documentation built on May 2, 2019, 3:33 p.m.