pete
pete

Reputation: 2406

Why does `:=` work as an infix operator?

Why does the following work in R?

> `:=` <- function(x, y) x + y
> 1 := 2
[1] 3

My understanding was that % was required for user-defined infix operators. Are there other (possibly easier to type) options available?

Upvotes: 11

Views: 378

Answers (1)

kohske
kohske

Reputation: 66902

This is because := is, like <- or <<-, defined as LEFT_ASSIGN for the parser of R.
See http://svn.r-project.org/R/trunk/src/main/gram.y

This means that := is a special case and you may as well not expect that any other options are available.

Upvotes: 11

Related Questions