I have come across the popular data.table
package and one thing in particular intrigued me. It has an in-place assignment operator
:=
This is not defined in base R. In fact if you didn't load the data.table
package, it would have raised an error if you had tried to used it (e.g., a := 2
) with the message:
Error: could not find function
":="
Also, why does :=
work? Why does R let you define :=
as infix operator while every other infix function has to be surrounded by %%
, e.g.
`:=` <- function(a, b) {
paste(a,b)
}
"abc" := "def"
Clearly it's not meant to be an alternative syntax to %function.name%
for defining infix functions. Is data.table
exploiting some parsing quirks of R? Is it a hack? Will it be "patched" in the future?
[
subsetting. So your question is off-base (not an R quirk) which is why I sent you to the data.table docs which discuss this. – Undeceive:=
<- function(a,b) paste(a,b); and I can use it by doing "abc" := "def"! But all other infix function are in the form of %in.fn%?. Why? – Hysterectomy